No compiler diagnostic when identifier in a simple-capture appears as the declarator-id of a parameter
Clash Royale CLAN TAG#URR8PPP
up vote
10
down vote
favorite
The section on lambda captures ([expr.prim.lambda.capture]/5) states that
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
Consider the follow example:
#include <iostream>
int main ()
auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);
GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.
Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:
// parameter and simple-capture have the same name
Godbolt Demo here
c++ language-lawyer
add a comment |Â
up vote
10
down vote
favorite
The section on lambda captures ([expr.prim.lambda.capture]/5) states that
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
Consider the follow example:
#include <iostream>
int main ()
auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);
GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.
Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:
// parameter and simple-capture have the same name
Godbolt Demo here
c++ language-lawyer
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
5
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
2
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
1
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago
add a comment |Â
up vote
10
down vote
favorite
up vote
10
down vote
favorite
The section on lambda captures ([expr.prim.lambda.capture]/5) states that
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
Consider the follow example:
#include <iostream>
int main ()
auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);
GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.
Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:
// parameter and simple-capture have the same name
Godbolt Demo here
c++ language-lawyer
The section on lambda captures ([expr.prim.lambda.capture]/5) states that
If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.
Consider the follow example:
#include <iostream>
int main ()
auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);
GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.
Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:
// parameter and simple-capture have the same name
Godbolt Demo here
c++ language-lawyer
c++ language-lawyer
edited 1 hour ago


Some programmer dude
287k24234395
287k24234395
asked 1 hour ago
P.W
5,6391331
5,6391331
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
5
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
2
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
1
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago
add a comment |Â
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
5
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
2
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
1
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
5
5
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
2
2
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
1
1
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
13
down vote
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
13
down vote
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
add a comment |Â
up vote
13
down vote
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
add a comment |Â
up vote
13
down vote
up vote
13
down vote
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.
It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.
answered 1 hour ago
StoryTeller
86.3k12173241
86.3k12173241
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%2f52947934%2fno-compiler-diagnostic-when-identifier-in-a-simple-capture-appears-as-the-declar%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
actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago
5
@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago
2
@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago
1
@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago