Why can std:set (with a single colon) compile?
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 |
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
12
std:
is interpreted as alabel
for agoto
. 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
add a comment |
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
c++ visual-studio
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 alabel
for agoto
. 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
add a comment |
12
std:
is interpreted as alabel
for agoto
. 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
add a comment |
2 Answers
2
active
oldest
votes
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 '18 at 3:40
32
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 '18 at 11:50
add a comment |
In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.
add a comment |
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
);
);
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
Required, but never shown
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
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 '18 at 3:40
32
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 '18 at 11:50
add a comment |
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 '18 at 3:40
32
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 '18 at 11:50
add a comment |
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 '18 at 3:03
BrianBrian
65.7k798186
65.7k798186
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 '18 at 3:40
32
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 '18 at 11:50
add a comment |
42
This is another reason to avoidusing namespace std;
andusing std::set;
– R Sahu
Aug 28 '18 at 3:40
32
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 '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
add a comment |
In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.
add a comment |
In the second case, std is a label. It is the same as spelling default incorrectly in a case statement.
add a comment |
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 '18 at 3:04
cupcup
4,71221026
4,71221026
add a comment |
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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
12
std:
is interpreted as alabel
for agoto
. 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