[llvm-bugs] [Bug 49053] New: Variable declared in if init statement sneaks into lambda expression
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Feb 5 01:12:06 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49053
Bug ID: 49053
Summary: Variable declared in if init statement sneaks into
lambda expression
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++17
Assignee: unassignedclangbugs at nondot.org
Reporter: sgiesecke at mozilla.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
The following code fails to compile with clang:
```
int main() {
if (auto foo = [] { int foo = 42; return true; }()) {}
}
```
saying
#1 with x86-64 clang (trunk)
<source>:2:29: error: redefinition of 'foo' with a different type: 'int' vs
'auto'
if (auto foo = [] { int foo = 42; return true; }()) {}
^
<source>:2:14: note: previous definition is here
if (auto foo = [] { int foo = 42; return true; }()) {}
^
1 error generated.
ASM generation compiler returned: 1
<source>:2:29: error: redefinition of 'foo' with a different type: 'int' vs
'auto'
if (auto foo = [] { int foo = 42; return true; }()) {}
^
<source>:2:14: note: previous definition is here
if (auto foo = [] { int foo = 42; return true; }()) {}
^
1 error generated.
Execution build compiler returned: 1
```
gcc accepts this code, and this seems right. The lambda expression does not
capture foo.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210205/d47f4e63/attachment-0001.html>
More information about the llvm-bugs
mailing list