Why is this const const const declaration valid

后端 未结 1 992
遇见更好的自我
遇见更好的自我 2021-02-04 02:52

A friend asked me to explain why

const const const const const int const i = 0;

is valid syntax. I declined to have any thoughts on the subjec

1条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 03:22

    From n1256:

    6.7.3/4

    If the same qualifier appears more than once in the same specifier-qualifier-list,either directly or via one or more typedefs, the behavior is the same as if it appeared only once.

    In C++, this should give an error.

    From C++03 standard:

    7.1.5/1 [dcl.type]

    As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration. The only exceptions to this rule are the following:

    — const or volatile can be combined with any other type-specifier. However, redundant cv- qualifiers are prohibited except when introduced through the use of typedefs (7.1.3) or template type arguments (14.3), in which case the redundant cv-qualifiers are ignored.

    From N3797 (C++11):

    7.1.6/2 [dcl.type]

    As a general rule, at most one type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailing-type-specifier-seq. The only exceptions to this rule are the following:

    — const can be combined with any type specifier except itself.
    

    0 讨论(0)
提交回复
热议问题