[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c++/97256] New: auto function return different result
From:       "tangyixuan at mail dot dlut.edu.cn via Gcc-bugs" <gcc-bugs () gcc ! gnu ! org>
Date:       2020-09-30 14:08:02
Message-ID: bug-97256-4 () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

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=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic