Why can std:set (with a single colon) compile?










64















I accidentally wrote



std::set<string> keys;


as:



std:set<string> keys;


but weirdly enough, Visual Studio 2013 still compiles.



Why does this happen?



Actually keys is not only defined, but later used as a set of strings, such as



if(keys.find(keystr)==keys.end())
keys.insert(keystr);
toret.push_back(tempv);










share|improve this question



















  • 12





    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

    – Sandburg
    Aug 28 '18 at 7:05







  • 10





    To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

    – Joshua
    Aug 28 '18 at 16:06






  • 5





    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

    – smci
    Aug 29 '18 at 0:40







  • 1





    @smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

    – Jonathon Reinhart
    Aug 29 '18 at 0:50






  • 2





    @JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

    – smci
    Aug 29 '18 at 1:41















64















I accidentally wrote



std::set<string> keys;


as:



std:set<string> keys;


but weirdly enough, Visual Studio 2013 still compiles.



Why does this happen?



Actually keys is not only defined, but later used as a set of strings, such as



if(keys.find(keystr)==keys.end())
keys.insert(keystr);
toret.push_back(tempv);










share|improve this question



















  • 12





    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

    – Sandburg
    Aug 28 '18 at 7:05







  • 10





    To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

    – Joshua
    Aug 28 '18 at 16:06






  • 5





    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

    – smci
    Aug 29 '18 at 0:40







  • 1





    @smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

    – Jonathon Reinhart
    Aug 29 '18 at 0:50






  • 2





    @JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

    – smci
    Aug 29 '18 at 1:41













64












64








64


2






I accidentally wrote



std::set<string> keys;


as:



std:set<string> keys;


but weirdly enough, Visual Studio 2013 still compiles.



Why does this happen?



Actually keys is not only defined, but later used as a set of strings, such as



if(keys.find(keystr)==keys.end())
keys.insert(keystr);
toret.push_back(tempv);










share|improve this question
















I accidentally wrote



std::set<string> keys;


as:



std:set<string> keys;


but weirdly enough, Visual Studio 2013 still compiles.



Why does this happen?



Actually keys is not only defined, but later used as a set of strings, such as



if(keys.find(keystr)==keys.end())
keys.insert(keystr);
toret.push_back(tempv);







c++ visual-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 28 '18 at 9:13









numbermaniac

63011427




63011427










asked Aug 28 '18 at 3:01









athosathos

2,21913166




2,21913166







  • 12





    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

    – Sandburg
    Aug 28 '18 at 7:05







  • 10





    To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

    – Joshua
    Aug 28 '18 at 16:06






  • 5





    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

    – smci
    Aug 29 '18 at 0:40







  • 1





    @smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

    – Jonathon Reinhart
    Aug 29 '18 at 0:50






  • 2





    @JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

    – smci
    Aug 29 '18 at 1:41












  • 12





    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

    – Sandburg
    Aug 28 '18 at 7:05







  • 10





    To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

    – Joshua
    Aug 28 '18 at 16:06






  • 5





    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

    – smci
    Aug 29 '18 at 0:40







  • 1





    @smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

    – Jonathon Reinhart
    Aug 29 '18 at 0:50






  • 2





    @JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

    – smci
    Aug 29 '18 at 1:41







12




12





std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

– Sandburg
Aug 28 '18 at 7:05






std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto

– Sandburg
Aug 28 '18 at 7:05





10




10





To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

– Joshua
Aug 28 '18 at 16:06





To those voting to close this thing, OP has identified the typo and wants to understand why it does what it does.

– Joshua
Aug 28 '18 at 16:06




5




5





Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

– smci
Aug 29 '18 at 0:40






Stop close-voting this, people. It's on-topic. We will just reopen it immediately.

– smci
Aug 29 '18 at 0:40





1




1





@smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

– Jonathon Reinhart
Aug 29 '18 at 0:50





@smci While I agree that this question should stay open, it's not really your place to tell people how to use their votes. Let them use theirs, and you use yours.

– Jonathon Reinhart
Aug 29 '18 at 0:50




2




2





@JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

– smci
Aug 29 '18 at 1:41





@JonathonReinhart: there's no dispute that it isn't on-topic, is there? Noone has suggested any reason why.

– smci
Aug 29 '18 at 1:41












2 Answers
2






active

oldest

votes


















97














At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:



set<string> keys;


except that it bears the label std and can be jumped to by the statement goto std;.



For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.






share|improve this answer


















  • 42





    This is another reason to avoid using namespace std; and using std::set;

    – R Sahu
    Aug 28 '18 at 3:40






  • 32





    There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

    – John P
    Aug 28 '18 at 11:50


















10














In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.






share|improve this answer






















    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%2f52049468%2fwhy-can-stdset-with-a-single-colon-compile%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    97














    At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:



    set<string> keys;


    except that it bears the label std and can be jumped to by the statement goto std;.



    For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.






    share|improve this answer


















    • 42





      This is another reason to avoid using namespace std; and using std::set;

      – R Sahu
      Aug 28 '18 at 3:40






    • 32





      There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

      – John P
      Aug 28 '18 at 11:50















    97














    At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:



    set<string> keys;


    except that it bears the label std and can be jumped to by the statement goto std;.



    For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.






    share|improve this answer


















    • 42





      This is another reason to avoid using namespace std; and using std::set;

      – R Sahu
      Aug 28 '18 at 3:40






    • 32





      There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

      – John P
      Aug 28 '18 at 11:50













    97












    97








    97







    At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:



    set<string> keys;


    except that it bears the label std and can be jumped to by the statement goto std;.



    For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.






    share|improve this answer













    At block scope, an identifier followed by a single colon introduces a label. Thus, your statement is equivalent to:



    set<string> keys;


    except that it bears the label std and can be jumped to by the statement goto std;.



    For some reason, the name set is known to the compiler---perhaps you did using namespace std;, or using std::set;, or something like that, or perhaps you defined your own set type somewhere.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Aug 28 '18 at 3:03









    BrianBrian

    65.7k798186




    65.7k798186







    • 42





      This is another reason to avoid using namespace std; and using std::set;

      – R Sahu
      Aug 28 '18 at 3:40






    • 32





      There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

      – John P
      Aug 28 '18 at 11:50












    • 42





      This is another reason to avoid using namespace std; and using std::set;

      – R Sahu
      Aug 28 '18 at 3:40






    • 32





      There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

      – John P
      Aug 28 '18 at 11:50







    42




    42





    This is another reason to avoid using namespace std; and using std::set;

    – R Sahu
    Aug 28 '18 at 3:40





    This is another reason to avoid using namespace std; and using std::set;

    – R Sahu
    Aug 28 '18 at 3:40




    32




    32





    There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

    – John P
    Aug 28 '18 at 11:50





    There are good arguments to be made against using namespace std/using std::set, but I'm not sure this is one of them... the main argument is usually that namespaces are there to prevent collisions, but if there is a non-std 'set' to collide with, then std: set<...> would probably be valid. Common practice is to limit any such using declarations to another namespace/function, but this problem could just as easily happen in that scope. I would sooner expect a typo to creep in rewriting std::chrono::high_resolution_clock, etc. ad nauseum than this label typo (the first I've seen like it.)

    – John P
    Aug 28 '18 at 11:50













    10














    In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.






    share|improve this answer



























      10














      In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.






      share|improve this answer

























        10












        10








        10







        In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.






        share|improve this answer













        In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 28 '18 at 3:04









        cupcup

        4,71221026




        4,71221026



























            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%2f52049468%2fwhy-can-stdset-with-a-single-colon-compile%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

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Crossroads (UK TV series)

            ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế