[Bug c++/97200] New: error: use of local variable with automatic storage from containing function

tangyixuan at mail dot dlut.edu.cn gcc-bugzilla@gcc.gnu.org
Fri Sep 25 07:54:50 GMT 2020


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

            Bug ID: 97200
           Summary: error: use of local variable with automatic storage
                    from containing function
           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, the following code seems valid. The structure 'S' contains a template
function 'func1' and return a member variable 'a'. However, gcc 11 rejects it
while clang accepts.

$ cat s.cpp

template <int> int func1(void) { 
  int  a; 
  struct S { 
    int func1(void){return a;} 
  };
}


$ g++ -c s.cpp
s.cpp: In member function ‘int func1()::S::func1()’:
s.cpp: error: use of local variable with automatic storage from containing
function
    4 |     int func1(void){return a;}
      |                            ^
s.cpp:2:8: note: ‘int a’ declared here
    2 |   int  a;
      |


More information about the Gcc-bugs mailing list