What is the rationale behind the differences between the compiler diagnostics issued when it sees std::vector and std::vector

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












12















Consider these two programs and their attempted compilations.



#include <vector>

int main()
std::vector<struct Typo> a; // Errors centered around `Typo` being an incomplete type



gcc 6.3, for example, gives error messages centered around Typo being an incomplete type, including




/usr/include/c++/6/bits/stl_vector.h:161:9: error: invalid use of incomplete type ‘struct main()::Typo




#include <vector>

int main()
std::vector<Typo> b; // Errors centred around `Typo` not being defined



gcc 6.3, for example, gives errors centered around Typo not being defined, including




prog.cpp:4:14: error: ‘Typo’ was not declared in this scope




Both vector instantiations are errors of course, but what is the rationale for the differing diagnostic messages as cited in the program comments?










share|improve this question



















  • 1





    Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

    – jrok
    Jan 31 at 12:52







  • 2





    @SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

    – Bathsheba
    Jan 31 at 12:54






  • 1





    @user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

    – jrok
    Jan 31 at 12:54






  • 1





    @Bathsheba Rather std::numeric_limits<Typo>::infinity().

    – Sombrero Chicken
    Jan 31 at 12:55






  • 2





    Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

    – aschepler
    Jan 31 at 13:06















12















Consider these two programs and their attempted compilations.



#include <vector>

int main()
std::vector<struct Typo> a; // Errors centered around `Typo` being an incomplete type



gcc 6.3, for example, gives error messages centered around Typo being an incomplete type, including




/usr/include/c++/6/bits/stl_vector.h:161:9: error: invalid use of incomplete type ‘struct main()::Typo




#include <vector>

int main()
std::vector<Typo> b; // Errors centred around `Typo` not being defined



gcc 6.3, for example, gives errors centered around Typo not being defined, including




prog.cpp:4:14: error: ‘Typo’ was not declared in this scope




Both vector instantiations are errors of course, but what is the rationale for the differing diagnostic messages as cited in the program comments?










share|improve this question



















  • 1





    Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

    – jrok
    Jan 31 at 12:52







  • 2





    @SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

    – Bathsheba
    Jan 31 at 12:54






  • 1





    @user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

    – jrok
    Jan 31 at 12:54






  • 1





    @Bathsheba Rather std::numeric_limits<Typo>::infinity().

    – Sombrero Chicken
    Jan 31 at 12:55






  • 2





    Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

    – aschepler
    Jan 31 at 13:06













12












12








12


2






Consider these two programs and their attempted compilations.



#include <vector>

int main()
std::vector<struct Typo> a; // Errors centered around `Typo` being an incomplete type



gcc 6.3, for example, gives error messages centered around Typo being an incomplete type, including




/usr/include/c++/6/bits/stl_vector.h:161:9: error: invalid use of incomplete type ‘struct main()::Typo




#include <vector>

int main()
std::vector<Typo> b; // Errors centred around `Typo` not being defined



gcc 6.3, for example, gives errors centered around Typo not being defined, including




prog.cpp:4:14: error: ‘Typo’ was not declared in this scope




Both vector instantiations are errors of course, but what is the rationale for the differing diagnostic messages as cited in the program comments?










share|improve this question
















Consider these two programs and their attempted compilations.



#include <vector>

int main()
std::vector<struct Typo> a; // Errors centered around `Typo` being an incomplete type



gcc 6.3, for example, gives error messages centered around Typo being an incomplete type, including




/usr/include/c++/6/bits/stl_vector.h:161:9: error: invalid use of incomplete type ‘struct main()::Typo




#include <vector>

int main()
std::vector<Typo> b; // Errors centred around `Typo` not being defined



gcc 6.3, for example, gives errors centered around Typo not being defined, including




prog.cpp:4:14: error: ‘Typo’ was not declared in this scope




Both vector instantiations are errors of course, but what is the rationale for the differing diagnostic messages as cited in the program comments?







c++ compiler-errors






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 31 at 13:06







Bathsheba

















asked Jan 31 at 12:47









BathshebaBathsheba

179k27254382




179k27254382







  • 1





    Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

    – jrok
    Jan 31 at 12:52







  • 2





    @SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

    – Bathsheba
    Jan 31 at 12:54






  • 1





    @user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

    – jrok
    Jan 31 at 12:54






  • 1





    @Bathsheba Rather std::numeric_limits<Typo>::infinity().

    – Sombrero Chicken
    Jan 31 at 12:55






  • 2





    Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

    – aschepler
    Jan 31 at 13:06












  • 1





    Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

    – jrok
    Jan 31 at 12:52







  • 2





    @SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

    – Bathsheba
    Jan 31 at 12:54






  • 1





    @user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

    – jrok
    Jan 31 at 12:54






  • 1





    @Bathsheba Rather std::numeric_limits<Typo>::infinity().

    – Sombrero Chicken
    Jan 31 at 12:55






  • 2





    Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

    – aschepler
    Jan 31 at 13:06







1




1





Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

– jrok
Jan 31 at 12:52






Because it's two different things? a) "You say there's a Typo, ok I get it, but it's incomplete". b) "There are no Typos around here, dude."

– jrok
Jan 31 at 12:52





2




2





@SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

– Bathsheba
Jan 31 at 12:54





@SombreroChicken: Am I a std::numeric_limits<Typo>::max()?

– Bathsheba
Jan 31 at 12:54




1




1





@user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

– jrok
Jan 31 at 12:54





@user463035818 It doesn't matter, how is compiler supposed to know it's a typo?

– jrok
Jan 31 at 12:54




1




1





@Bathsheba Rather std::numeric_limits<Typo>::infinity().

– Sombrero Chicken
Jan 31 at 12:55





@Bathsheba Rather std::numeric_limits<Typo>::infinity().

– Sombrero Chicken
Jan 31 at 12:55




2




2





Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

– aschepler
Jan 31 at 13:06





Edited to be two programs, since it seems that's what you're actually asking about, and to specify gcc 6.3.

– aschepler
Jan 31 at 13:06












1 Answer
1






active

oldest

votes


















15














struct Typo is an elaborated type specifier. That affects how name lookup works.




[basic.lookup.elab]



2: If the elaborated-type-specifier has no nested-name-specifier,
and unless the elaborated-type-specifier appears in a declaration with
the following form:



class-key attribute-specifier-seq identifier ;


the identifier is looked up according to [basic.lookup.unqual] but
ignoring any non-type names that have been declared. If the
elaborated-type-specifier is introduced by the enum keyword and this
lookup does not find a previously declared type-name, the
elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier is introduced by the class-key and this
lookup does not find a previously declared type-name, or if the
elaborated-type-specifier appears in a declaration with the form:



class-key attribute-specifier-seq identifier ;


the elaborated-type-specifier is a declaration that introduces the
class-name as described in [basic.scope.pdecl].




So in std::vector<struct Typo> a;, because struct Typo does not find a previously declared Typo, it serves as a forward declaration for the type. And as such, its the vector instantiation that may1 complain the type it got is incomplete because it will try to do stuff with it.



While in std::vector<Typo> b;, looking up Typo finds nothing. There is no previous declaration for it, so its at this point a diagnostic should be issued that this identifier is undeclared.




1 - Depends on what standard you are compiling to, and what members of the vector you are using. Support for incomplete types has been added.






share|improve this answer




















  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    Jan 31 at 12:53











  • @Bathsheba - I'm not gonna complain :)

    – StoryTeller
    Jan 31 at 12:53






  • 1





    @Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

    – StoryTeller
    Jan 31 at 12:57







  • 1





    @jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

    – P i
    Jan 31 at 13:05







  • 1





    Ho man, that footnote killed me!

    – YSC
    Jan 31 at 16:51










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%2f54460967%2fwhat-is-the-rationale-behind-the-differences-between-the-compiler-diagnostics-is%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









15














struct Typo is an elaborated type specifier. That affects how name lookup works.




[basic.lookup.elab]



2: If the elaborated-type-specifier has no nested-name-specifier,
and unless the elaborated-type-specifier appears in a declaration with
the following form:



class-key attribute-specifier-seq identifier ;


the identifier is looked up according to [basic.lookup.unqual] but
ignoring any non-type names that have been declared. If the
elaborated-type-specifier is introduced by the enum keyword and this
lookup does not find a previously declared type-name, the
elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier is introduced by the class-key and this
lookup does not find a previously declared type-name, or if the
elaborated-type-specifier appears in a declaration with the form:



class-key attribute-specifier-seq identifier ;


the elaborated-type-specifier is a declaration that introduces the
class-name as described in [basic.scope.pdecl].




So in std::vector<struct Typo> a;, because struct Typo does not find a previously declared Typo, it serves as a forward declaration for the type. And as such, its the vector instantiation that may1 complain the type it got is incomplete because it will try to do stuff with it.



While in std::vector<Typo> b;, looking up Typo finds nothing. There is no previous declaration for it, so its at this point a diagnostic should be issued that this identifier is undeclared.




1 - Depends on what standard you are compiling to, and what members of the vector you are using. Support for incomplete types has been added.






share|improve this answer




















  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    Jan 31 at 12:53











  • @Bathsheba - I'm not gonna complain :)

    – StoryTeller
    Jan 31 at 12:53






  • 1





    @Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

    – StoryTeller
    Jan 31 at 12:57







  • 1





    @jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

    – P i
    Jan 31 at 13:05







  • 1





    Ho man, that footnote killed me!

    – YSC
    Jan 31 at 16:51















15














struct Typo is an elaborated type specifier. That affects how name lookup works.




[basic.lookup.elab]



2: If the elaborated-type-specifier has no nested-name-specifier,
and unless the elaborated-type-specifier appears in a declaration with
the following form:



class-key attribute-specifier-seq identifier ;


the identifier is looked up according to [basic.lookup.unqual] but
ignoring any non-type names that have been declared. If the
elaborated-type-specifier is introduced by the enum keyword and this
lookup does not find a previously declared type-name, the
elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier is introduced by the class-key and this
lookup does not find a previously declared type-name, or if the
elaborated-type-specifier appears in a declaration with the form:



class-key attribute-specifier-seq identifier ;


the elaborated-type-specifier is a declaration that introduces the
class-name as described in [basic.scope.pdecl].




So in std::vector<struct Typo> a;, because struct Typo does not find a previously declared Typo, it serves as a forward declaration for the type. And as such, its the vector instantiation that may1 complain the type it got is incomplete because it will try to do stuff with it.



While in std::vector<Typo> b;, looking up Typo finds nothing. There is no previous declaration for it, so its at this point a diagnostic should be issued that this identifier is undeclared.




1 - Depends on what standard you are compiling to, and what members of the vector you are using. Support for incomplete types has been added.






share|improve this answer




















  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    Jan 31 at 12:53











  • @Bathsheba - I'm not gonna complain :)

    – StoryTeller
    Jan 31 at 12:53






  • 1





    @Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

    – StoryTeller
    Jan 31 at 12:57







  • 1





    @jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

    – P i
    Jan 31 at 13:05







  • 1





    Ho man, that footnote killed me!

    – YSC
    Jan 31 at 16:51













15












15








15







struct Typo is an elaborated type specifier. That affects how name lookup works.




[basic.lookup.elab]



2: If the elaborated-type-specifier has no nested-name-specifier,
and unless the elaborated-type-specifier appears in a declaration with
the following form:



class-key attribute-specifier-seq identifier ;


the identifier is looked up according to [basic.lookup.unqual] but
ignoring any non-type names that have been declared. If the
elaborated-type-specifier is introduced by the enum keyword and this
lookup does not find a previously declared type-name, the
elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier is introduced by the class-key and this
lookup does not find a previously declared type-name, or if the
elaborated-type-specifier appears in a declaration with the form:



class-key attribute-specifier-seq identifier ;


the elaborated-type-specifier is a declaration that introduces the
class-name as described in [basic.scope.pdecl].




So in std::vector<struct Typo> a;, because struct Typo does not find a previously declared Typo, it serves as a forward declaration for the type. And as such, its the vector instantiation that may1 complain the type it got is incomplete because it will try to do stuff with it.



While in std::vector<Typo> b;, looking up Typo finds nothing. There is no previous declaration for it, so its at this point a diagnostic should be issued that this identifier is undeclared.




1 - Depends on what standard you are compiling to, and what members of the vector you are using. Support for incomplete types has been added.






share|improve this answer















struct Typo is an elaborated type specifier. That affects how name lookup works.




[basic.lookup.elab]



2: If the elaborated-type-specifier has no nested-name-specifier,
and unless the elaborated-type-specifier appears in a declaration with
the following form:



class-key attribute-specifier-seq identifier ;


the identifier is looked up according to [basic.lookup.unqual] but
ignoring any non-type names that have been declared. If the
elaborated-type-specifier is introduced by the enum keyword and this
lookup does not find a previously declared type-name, the
elaborated-type-specifier is ill-formed. If the
elaborated-type-specifier is introduced by the class-key and this
lookup does not find a previously declared type-name, or if the
elaborated-type-specifier appears in a declaration with the form:



class-key attribute-specifier-seq identifier ;


the elaborated-type-specifier is a declaration that introduces the
class-name as described in [basic.scope.pdecl].




So in std::vector<struct Typo> a;, because struct Typo does not find a previously declared Typo, it serves as a forward declaration for the type. And as such, its the vector instantiation that may1 complain the type it got is incomplete because it will try to do stuff with it.



While in std::vector<Typo> b;, looking up Typo finds nothing. There is no previous declaration for it, so its at this point a diagnostic should be issued that this identifier is undeclared.




1 - Depends on what standard you are compiling to, and what members of the vector you are using. Support for incomplete types has been added.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 31 at 13:07

























answered Jan 31 at 12:52









StoryTellerStoryTeller

99.3k12201271




99.3k12201271







  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    Jan 31 at 12:53











  • @Bathsheba - I'm not gonna complain :)

    – StoryTeller
    Jan 31 at 12:53






  • 1





    @Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

    – StoryTeller
    Jan 31 at 12:57







  • 1





    @jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

    – P i
    Jan 31 at 13:05







  • 1





    Ho man, that footnote killed me!

    – YSC
    Jan 31 at 16:51












  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    Jan 31 at 12:53











  • @Bathsheba - I'm not gonna complain :)

    – StoryTeller
    Jan 31 at 12:53






  • 1





    @Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

    – StoryTeller
    Jan 31 at 12:57







  • 1





    @jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

    – P i
    Jan 31 at 13:05







  • 1





    Ho man, that footnote killed me!

    – YSC
    Jan 31 at 16:51







1




1





elaborate type specifier - that's posh.

– Bathsheba
Jan 31 at 12:53





elaborate type specifier - that's posh.

– Bathsheba
Jan 31 at 12:53













@Bathsheba - I'm not gonna complain :)

– StoryTeller
Jan 31 at 12:53





@Bathsheba - I'm not gonna complain :)

– StoryTeller
Jan 31 at 12:53




1




1





@Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

– StoryTeller
Jan 31 at 12:57






@Pi - No, I did not say that. The declaration is known. But the vector tries to use an incomplete type in a way that is not allowed (create objects of it, for instance).

– StoryTeller
Jan 31 at 12:57





1




1





@jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

– P i
Jan 31 at 13:05






@jrok DOHHH!!!!!!!!!!!!!!!!!!!! :) No more to add. Typo was well chosen. Thanks for pointing out :D

– P i
Jan 31 at 13:05





1




1





Ho man, that footnote killed me!

– YSC
Jan 31 at 16:51





Ho man, that footnote killed me!

– YSC
Jan 31 at 16:51



















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%2f54460967%2fwhat-is-the-rationale-behind-the-differences-between-the-compiler-diagnostics-is%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

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?