https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256

            Bug ID: 97256
           Summary: auto function return different result
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tangyixuan at mail dot dlut.edu.cn
  Target Milestone: ---

Hi, when executing the following code, GCC reports 32765 while clang reports 1. 
Maybe there is something wrong?
$ cat s.cpp

#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

Reply via email to