This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81998] New: [c++14] lambda: name from init-capture not visible in lambda-declarator
- From: "aschepler at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 27 Aug 2017 16:04:06 +0000
- Subject: [Bug c++/81998] New: [c++14] lambda: name from init-capture not visible in lambda-declarator
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81998
Bug ID: 81998
Summary: [c++14] lambda: name from init-capture not visible in
lambda-declarator
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: aschepler at gmail dot com
Target Milestone: ---
g++ 7.2.0 rejects this well-formed minimal code, whether using -std=c++14 or
-std=c++1z:
void f() {
[x=2] (decltype(x)) {};
}
Errors:
main.cpp: In function 'void f()':
main.cpp:2:20: error: 'x' was not declared in this scope
[x=2](decltype(x)) {};
^
main.cpp:2:20: error: 'x' was not declared in this scope
C++14 [expr.prim.lambda]/11 says: "Within the lambda-expressions
lambda-declarator and compound-statement, the identifier in the init-capture
hides any declaration of the same name in scopes enclosing the
lambda-expression."
This implies the identifier ("x") from the init-capture ("x=2") should be in
scope within the lambda-declarator ("(decltype(x))").