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












11















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
    yesterday








  • 2





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

    – Bathsheba
    yesterday






  • 1





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

    – jrok
    yesterday






  • 1





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

    – Sombrero Chicken
    yesterday






  • 2





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

    – aschepler
    yesterday
















11















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
    yesterday








  • 2





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

    – Bathsheba
    yesterday






  • 1





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

    – jrok
    yesterday






  • 1





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

    – Sombrero Chicken
    yesterday






  • 2





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

    – aschepler
    yesterday














11












11








11


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 yesterday







Bathsheba

















asked yesterday









BathshebaBathsheba

178k27254378




178k27254378








  • 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
    yesterday








  • 2





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

    – Bathsheba
    yesterday






  • 1





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

    – jrok
    yesterday






  • 1





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

    – Sombrero Chicken
    yesterday






  • 2





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

    – aschepler
    yesterday














  • 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
    yesterday








  • 2





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

    – Bathsheba
    yesterday






  • 1





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

    – jrok
    yesterday






  • 1





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

    – Sombrero Chicken
    yesterday






  • 2





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

    – aschepler
    yesterday








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
yesterday







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
yesterday






2




2





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

– Bathsheba
yesterday





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

– Bathsheba
yesterday




1




1





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

– jrok
yesterday





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

– jrok
yesterday




1




1





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

– Sombrero Chicken
yesterday





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

– Sombrero Chicken
yesterday




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
yesterday





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

– aschepler
yesterday












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
    yesterday











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

    – StoryTeller
    yesterday






  • 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
    yesterday








  • 1





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

    – P i
    yesterday








  • 1





    Ho man, that footnote killed me!

    – YSC
    yesterday











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
    yesterday











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

    – StoryTeller
    yesterday






  • 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
    yesterday








  • 1





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

    – P i
    yesterday








  • 1





    Ho man, that footnote killed me!

    – YSC
    yesterday
















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
    yesterday











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

    – StoryTeller
    yesterday






  • 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
    yesterday








  • 1





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

    – P i
    yesterday








  • 1





    Ho man, that footnote killed me!

    – YSC
    yesterday














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 yesterday

























answered yesterday









StoryTellerStoryTeller

97.5k12199265




97.5k12199265








  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    yesterday











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

    – StoryTeller
    yesterday






  • 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
    yesterday








  • 1





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

    – P i
    yesterday








  • 1





    Ho man, that footnote killed me!

    – YSC
    yesterday














  • 1





    elaborate type specifier - that's posh.

    – Bathsheba
    yesterday











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

    – StoryTeller
    yesterday






  • 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
    yesterday








  • 1





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

    – P i
    yesterday








  • 1





    Ho man, that footnote killed me!

    – YSC
    yesterday








1




1





elaborate type specifier - that's posh.

– Bathsheba
yesterday





elaborate type specifier - that's posh.

– Bathsheba
yesterday













@Bathsheba - I'm not gonna complain :)

– StoryTeller
yesterday





@Bathsheba - I'm not gonna complain :)

– StoryTeller
yesterday




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
yesterday







@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
yesterday






1




1





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

– P i
yesterday







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

– P i
yesterday






1




1





Ho man, that footnote killed me!

– YSC
yesterday





Ho man, that footnote killed me!

– YSC
yesterday


















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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?