Duplicate CV qualifiers












1















I have a simple piece of code:



const const int a = 10;


It fails to compile with gcc:



error: duplicate 'const'


However clang compiles it with a warning:



warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]


Microsoft compiler also generates a warning.



Also situation with volatile qualifier is the same.



From the [dcl.type] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf):




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



(2.1)
const can be combined with any type specifier except itself.



(2.2)
volatile can be combined with any type specifier except itself.



(2.3)
signed or unsigned can be combined with char, long, short, or int.



(2.4)
short or long can be combined with int.



(2.5)
long can be combined with double.



(2.6)
long can be combined with long.




So I don't quite understand what does "as a general rule" means. Is this formally valid or not?



Also I found the related issue Duplicate const qualifier allowed in C but not in C++?, but there discussion is mainly about c and c++ differences.










share|improve this question

























  • Which version of the standard are you quoting from? Which draft?

    – Some programmer dude
    Nov 22 '18 at 6:48











  • Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

    – Seleznev Anton
    Nov 22 '18 at 6:54













  • eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

    – StoryTeller
    Nov 22 '18 at 6:58











  • It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

    – Some programmer dude
    Nov 22 '18 at 7:00













  • Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

    – Seleznev Anton
    Nov 22 '18 at 7:03
















1















I have a simple piece of code:



const const int a = 10;


It fails to compile with gcc:



error: duplicate 'const'


However clang compiles it with a warning:



warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]


Microsoft compiler also generates a warning.



Also situation with volatile qualifier is the same.



From the [dcl.type] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf):




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



(2.1)
const can be combined with any type specifier except itself.



(2.2)
volatile can be combined with any type specifier except itself.



(2.3)
signed or unsigned can be combined with char, long, short, or int.



(2.4)
short or long can be combined with int.



(2.5)
long can be combined with double.



(2.6)
long can be combined with long.




So I don't quite understand what does "as a general rule" means. Is this formally valid or not?



Also I found the related issue Duplicate const qualifier allowed in C but not in C++?, but there discussion is mainly about c and c++ differences.










share|improve this question

























  • Which version of the standard are you quoting from? Which draft?

    – Some programmer dude
    Nov 22 '18 at 6:48











  • Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

    – Seleznev Anton
    Nov 22 '18 at 6:54













  • eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

    – StoryTeller
    Nov 22 '18 at 6:58











  • It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

    – Some programmer dude
    Nov 22 '18 at 7:00













  • Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

    – Seleznev Anton
    Nov 22 '18 at 7:03














1












1








1








I have a simple piece of code:



const const int a = 10;


It fails to compile with gcc:



error: duplicate 'const'


However clang compiles it with a warning:



warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]


Microsoft compiler also generates a warning.



Also situation with volatile qualifier is the same.



From the [dcl.type] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf):




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



(2.1)
const can be combined with any type specifier except itself.



(2.2)
volatile can be combined with any type specifier except itself.



(2.3)
signed or unsigned can be combined with char, long, short, or int.



(2.4)
short or long can be combined with int.



(2.5)
long can be combined with double.



(2.6)
long can be combined with long.




So I don't quite understand what does "as a general rule" means. Is this formally valid or not?



Also I found the related issue Duplicate const qualifier allowed in C but not in C++?, but there discussion is mainly about c and c++ differences.










share|improve this question
















I have a simple piece of code:



const const int a = 10;


It fails to compile with gcc:



error: duplicate 'const'


However clang compiles it with a warning:



warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]


Microsoft compiler also generates a warning.



Also situation with volatile qualifier is the same.



From the [dcl.type] (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf):




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



(2.1)
const can be combined with any type specifier except itself.



(2.2)
volatile can be combined with any type specifier except itself.



(2.3)
signed or unsigned can be combined with char, long, short, or int.



(2.4)
short or long can be combined with int.



(2.5)
long can be combined with double.



(2.6)
long can be combined with long.




So I don't quite understand what does "as a general rule" means. Is this formally valid or not?



Also I found the related issue Duplicate const qualifier allowed in C but not in C++?, but there discussion is mainly about c and c++ differences.







c++ const volatile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:48







Seleznev Anton

















asked Nov 22 '18 at 6:47









Seleznev AntonSeleznev Anton

374212




374212













  • Which version of the standard are you quoting from? Which draft?

    – Some programmer dude
    Nov 22 '18 at 6:48











  • Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

    – Seleznev Anton
    Nov 22 '18 at 6:54













  • eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

    – StoryTeller
    Nov 22 '18 at 6:58











  • It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

    – Some programmer dude
    Nov 22 '18 at 7:00













  • Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

    – Seleznev Anton
    Nov 22 '18 at 7:03



















  • Which version of the standard are you quoting from? Which draft?

    – Some programmer dude
    Nov 22 '18 at 6:48











  • Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

    – Seleznev Anton
    Nov 22 '18 at 6:54













  • eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

    – StoryTeller
    Nov 22 '18 at 6:58











  • It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

    – Some programmer dude
    Nov 22 '18 at 7:00













  • Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

    – Seleznev Anton
    Nov 22 '18 at 7:03

















Which version of the standard are you quoting from? Which draft?

– Some programmer dude
Nov 22 '18 at 6:48





Which version of the standard are you quoting from? Which draft?

– Some programmer dude
Nov 22 '18 at 6:48













Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

– Seleznev Anton
Nov 22 '18 at 6:54







Get it from eel.is/c++draft/dcl.type. Actually I don't know to what version of the c++ standard it refers to.

– Seleznev Anton
Nov 22 '18 at 6:54















eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

– StoryTeller
Nov 22 '18 at 6:58





eel.is holds the current tip of the C++ standard working draft. It's not a draft for a published version, but for a future version (C++20).

– StoryTeller
Nov 22 '18 at 6:58













It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

– Some programmer dude
Nov 22 '18 at 7:00







It's probably the latest C++20 draft, but the source directly used to generate the web-pages have commits not part of the C++ standard repository so I'd be a little bit wary of it.

– Some programmer dude
Nov 22 '18 at 7:00















Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

– Seleznev Anton
Nov 22 '18 at 7:03





Found open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4713.pdf for c++17. The same is written there. Updated link in the question.

– Seleznev Anton
Nov 22 '18 at 7:03












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425271%2fduplicate-cv-qualifiers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425271%2fduplicate-cv-qualifiers%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin