Why doesn't the compiler give an error when the typedef const pointer is used with an extra const?

The following is the error as expected:

int* const const p = new int; // g++ error: duplicate cv-qualifier

But below there is no error, even if it is equivalent to the previous one:

typedef int* const intp_const;
intp_const const p = new int;  // ok !
        // ^^^^^ duplicate ?

Why constdoes the compiler ignore extra ?

[Note: intp_const constdoes not match const char* constbecause it is possible *p = <value>;.]

+5
source share
3 answers

In 7.1.5 [dcl.type] (C ++ 03) it is indicated that redundant cv-qualifiers are allowed when entering through typedef:

const volatile . cv- , , typedefs (7.1.3) (14.3), cv- .

+12

7.1.6 p 2 const decl-specifier-seq

, --seq --seq ---seq . :

- const , .

7.1.6.1 p 1 typedef:

cv-, const volatile. --seq cv, init-declarator . [: 3.9.3 8.3.5 , cv- . - end note] cv- . [. , typedefs. - ]

+6

, typedefs - , , , , . , , const, . , , .

const, , , .

0
source

All Articles