[llvm-bugs] [Bug 47702] New: auto function return the reference of a local variable not the value
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Oct 1 05:39:47 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47702
Bug ID: 47702
Summary: auto function return the reference of a local variable
not the value
Product: clang
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: tangyixuan at mail.dlut.edu.cn
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Hi, the following code returns the value of a local variable instead of the
reference address. At first I though it was a gcc bug and reported it to gcc.
Maybe is miscompiled by clang.
#include <iostream>
auto func(const int a) {
const int b = a;
return [&](){ return b; };
}
int main() {
auto c = func(1);
std::cout << c() ;
return 0;
}
$ g++ -std=c++2a s.cpp
$ ./a.out
32765
$ clang++ -std=c++2a s.cpp
$ ./a.out
1
reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
--
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/20201001/32ae21db/attachment-0001.html>
More information about the llvm-bugs
mailing list