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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to