Why can std:set (with a single colon) compile?
Clash Royale CLAN TAG#URR8PPP
up vote
55
down vote
favorite
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
add a comment |Â
up vote
55
down vote
favorite
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
10
std:
is interpreted as alabel
for agoto
. 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
add a comment |Â
up vote
55
down vote
favorite
up vote
55
down vote
favorite
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
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
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 alabel
for agoto
. 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
add a comment |Â
10
std:
is interpreted as alabel
for agoto
. 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
add a comment |Â
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.
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 at 3:40
31
There are good arguments to be made againstusing 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, thenstd: 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 rewritingstd::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
add a comment |Â
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.
add a comment |Â
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.
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 at 3:40
31
There are good arguments to be made againstusing 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, thenstd: 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 rewritingstd::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
add a comment |Â
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.
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 at 3:40
31
There are good arguments to be made againstusing 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, thenstd: 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 rewritingstd::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
add a comment |Â
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.
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.
answered Aug 28 at 3:03


Brian
60k791173
60k791173
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 at 3:40
31
There are good arguments to be made againstusing 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, thenstd: 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 rewritingstd::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
add a comment |Â
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 at 3:40
31
There are good arguments to be made againstusing 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, thenstd: 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 rewritingstd::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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.
answered Aug 28 at 3:04


cup
4,5802924
4,5802924
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
10
std:
is interpreted as alabel
for agoto
. 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