Four-digit "const" in function definition

I am wondering how C ++ uses the const keyword.

I have the following function definition. Which in itself looks completely insane, but it works fine.

const int const * const Get(){ return new int(1); } const

I know what each placement of a constant means, this question is not about the value of the placement of the const keyword.

I am very confused about using const keywords because you can duplicate them.

const int const const * const Get(){ return new int(1); } const

// or even

const const int const const * const const Get(){ return new int(1); } const const

// or even yet

const const const int const const const * const const const Get(){ return new int(1); } const const const

Why does language allow you to do this?

EDIT: This code can be compiled in Visual Studio 2013, the Visual C ++ Compiler. I am not sure about the actual name of the compiler.

EDIT2: So the answer is that this is against the standard. The code compiles without using the option /Za.

I vote to close the question.

+4
5

const .

[dcl.type]/2 ( )

, - --seq -seq --seq.

...

- const , .

, ( @davidhigh):

[dcl.type.cv]/1

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

, const, typedef s, , .

:

const const int const const * const const Get(){ return new int(1); } const const

const int, , .

const .

const Get. , , , , ++.

VS2013 , . gcc 5.1.0 clang 3.5.1 .

+10

Re

" ?"

. - . .

const int const * const Get(){ return new int(1); } const

( ) - :

  • const ( int) .
  • const - .

: ++ 11 §7.1.6/2,

" const , .

+3

? . [dcl.type.cv], ( ):

cv-, const volatile. cv- cv-qualifier-seq. --seq cv, -- . [: 3.9.3 8.3.5 , cv- . - ] cv- . [. , typedefs. - ]

, . const, , -.


: , , . [dcl.type], const (. @TartanLlama ).


2: , -, : const , - , .

, , .

, : const s, , const (, , ).

, , , . , , - .

+2

( )

const int const * const Get(){ return new int(1); } const;

, ++ (7.1.6 , # 2)

- const , .

(7.1.6.1 cv-)

1 cv-, const volatile. cv- cvqualifier-seq.

, , const

const int const * const Get(){ return new int(1); } const;
^^^^^     ^^^^^

, .:)

const int const * const Get(){ return new int(1); } const;
                                                    ^^^^^ 

const int const * const Get() const { return new int(1); };
                              ^^^^^ 

( cv-qualifier), , cv- const

const const int const const * const const Get() const const { return new int(1); };
                                                ^^^^^ ^^^^^

++ C . .

const long const long const int const x = 10;

const long long int x = 10;

++ .

0

.

  • MSVC (C4114) , . , , , , .

  • const , . :

    const const int const const * const const Get(){ return new int(1); } const const
    
    int main() {}
    

    It is actually

    const const int const const * const const Get(){ return new int(1); } 
    
    const const int main() {}
    

    which is "OK" modulo part of the re-qualifiers.

0
source

All Articles