public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97200] New: error: use of local variable with automatic storage from containing function
@ 2020-09-25 7:54 tangyixuan at mail dot dlut.edu.cn
2020-09-25 8:31 ` [Bug c++/97200] " rguenth at gcc dot gnu.org
2021-07-24 17:10 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: tangyixuan at mail dot dlut.edu.cn @ 2020-09-25 7:54 UTC (permalink / raw)
To: gcc-bugs
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;
|
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/97200] error: use of local variable with automatic storage from containing function
2020-09-25 7:54 [Bug c++/97200] New: error: use of local variable with automatic storage from containing function tangyixuan at mail dot dlut.edu.cn
@ 2020-09-25 8:31 ` rguenth at gcc dot gnu.org
2021-07-24 17:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-25 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97200
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
clang rejects it as well as soon as you instantiate func1:
t3.ii:4:28: error: reference to local variable 'a' declared in enclosing
function 'func1<1>'
int func1(void){return a;}
^
t3.ii:3:10: note: in instantiation of member function 'func1()::S::func1'
requested here
struct S {
^
t3.ii:8:14: note: in instantiation of function template specialization
'func1<1>' requested here
template int func1<1> ();
^
t3.ii:2:8: note: 'a' declared here
int a;
^
1 error generated.
it looks like a correct error to me, not sure if the use of 'a' is dependent
and thus the error should be delayed to allow SFINAE (not sure if that exists
for function templates).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/97200] error: use of local variable with automatic storage from containing function
2020-09-25 7:54 [Bug c++/97200] New: error: use of local variable with automatic storage from containing function tangyixuan at mail dot dlut.edu.cn
2020-09-25 8:31 ` [Bug c++/97200] " rguenth at gcc dot gnu.org
@ 2021-07-24 17:10 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-24 17:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97200
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 57346.
*** This bug has been marked as a duplicate of bug 57346 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-07-24 17:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 7:54 [Bug c++/97200] New: error: use of local variable with automatic storage from containing function tangyixuan at mail dot dlut.edu.cn
2020-09-25 8:31 ` [Bug c++/97200] " rguenth at gcc dot gnu.org
2021-07-24 17:10 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).