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

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











up vote
55
down vote

favorite
1












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


















  • 10




    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
    – Sandburg
    Aug 28 at 7:05







  • 8




    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 at 16:06






  • 5




    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
    – smci
    Aug 29 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 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 at 1:41














up vote
55
down vote

favorite
1












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


















  • 10




    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
    – Sandburg
    Aug 28 at 7:05







  • 8




    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 at 16:06






  • 5




    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
    – smci
    Aug 29 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 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 at 1:41












up vote
55
down vote

favorite
1









up vote
55
down vote

favorite
1






1





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);









share|improve this question













share|improve this question




share|improve this question








edited Aug 28 at 9:13









numbermaniac

62011225




62011225










asked Aug 28 at 3:01









athos

2,04012858




2,04012858







  • 10




    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
    – Sandburg
    Aug 28 at 7:05







  • 8




    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 at 16:06






  • 5




    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
    – smci
    Aug 29 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 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 at 1:41












  • 10




    std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
    – Sandburg
    Aug 28 at 7:05







  • 8




    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 at 16:06






  • 5




    Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
    – smci
    Aug 29 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 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 at 1:41







10




10




std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
– Sandburg
Aug 28 at 7:05





std: is interpreted as a label for a goto. see: en.cppreference.com/w/cpp/language/goto
– Sandburg
Aug 28 at 7:05





8




8




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 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 at 16:06




5




5




Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
– smci
Aug 29 at 0:40





Stop close-voting this, people. It's on-topic. We will just reopen it immediately.
– smci
Aug 29 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 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 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 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 at 1:41












2 Answers
2






active

oldest

votes

















up vote
90
down vote



accepted










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 at 3:40






  • 31




    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 at 11:50

















up vote
10
down vote













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',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    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






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    90
    down vote



    accepted










    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 at 3:40






    • 31




      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 at 11:50














    up vote
    90
    down vote



    accepted










    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 at 3:40






    • 31




      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 at 11:50












    up vote
    90
    down vote



    accepted







    up vote
    90
    down vote



    accepted






    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 at 3:03









    Brian

    60k791173




    60k791173







    • 42




      This is another reason to avoid using namespace std; and using std::set;
      – R Sahu
      Aug 28 at 3:40






    • 31




      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 at 11:50












    • 42




      This is another reason to avoid using namespace std; and using std::set;
      – R Sahu
      Aug 28 at 3:40






    • 31




      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 at 11:50







    42




    42




    This is another reason to avoid using namespace std; and using std::set;
    – R Sahu
    Aug 28 at 3:40




    This is another reason to avoid using namespace std; and using std::set;
    – R Sahu
    Aug 28 at 3:40




    31




    31




    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 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 at 11:50












    up vote
    10
    down vote













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






    share|improve this answer
























      up vote
      10
      down vote













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






      share|improve this answer






















        up vote
        10
        down vote










        up vote
        10
        down vote









        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 at 3:04









        cup

        4,5802924




        4,5802924



























             

            draft saved


            draft discarded















































             


            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery