using vs. typedef - is there a subtle, lesser known difference?

后端 未结 2 1761
小鲜肉
小鲜肉 2021-01-01 12:02

Background

Everybody agrees that

using  = ;

is equivalent to

typedef          


        
2条回答
  •  情深已故
    2021-01-01 12:26

    This looks to me like a bug in GCC.

    Note that [decl.typedef] does not say that an alias declaration is a typedef declaration

    You're right, [dcl.dcl]p9 gives a definition of the term typedef declaration which excludes alias-declarations. However, [dcl.typedef] does explicitly say, as you quoted in your question:

    2 A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by the typedef specifier. [...]

    "The same semantics" doesn't leave any doubt. Under GCC's interpretation, typedef and using have different semantics, therefore the only reasonable conclusion is that GCC's interpretation is wrong. Any rules applying to typedef declarations must be interpreted as applying to alias-declarations as well.

提交回复
热议问题