public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97256] New: auto function return different result
@ 2020-09-30 14:08 tangyixuan at mail dot dlut.edu.cn
2020-09-30 15:00 ` [Bug c++/97256] " rguenth at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: tangyixuan at mail dot dlut.edu.cn @ 2020-09-30 14:08 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
@ 2020-09-30 15:00 ` rguenth at gcc dot gnu.org
2020-10-01 10:01 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-30 15:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
possibly this returns a reference to a local variable which is undefined?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
2020-09-30 15:00 ` [Bug c++/97256] " rguenth at gcc dot gnu.org
@ 2020-10-01 10:01 ` redi at gcc dot gnu.org
2020-10-01 10:01 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-01 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes, the lambda captures a local variable by value, and then when you invoke
the lambda it refers to a dead variable.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
2020-09-30 15:00 ` [Bug c++/97256] " rguenth at gcc dot gnu.org
2020-10-01 10:01 ` redi at gcc dot gnu.org
@ 2020-10-01 10:01 ` redi at gcc dot gnu.org
2020-10-02 1:00 ` richard-gccbugzilla at metafoo dot co.uk
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-01 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #2)
> Yes, the lambda captures a local variable by value,
Duh, sorry, I meant captures a local variables BY REFERENCE.
> and then when you invoke
> the lambda it refers to a dead variable.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
` (2 preceding siblings ...)
2020-10-01 10:01 ` redi at gcc dot gnu.org
@ 2020-10-02 1:00 ` richard-gccbugzilla at metafoo dot co.uk
2020-10-02 1:04 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-10-02 1:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
Richard Smith <richard-gccbugzilla at metafoo dot co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |richard-gccbugzilla@metafoo
| |.co.uk
--- Comment #4 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
The reference to 'b' from within the lambda is not an odr-use, so is not
transformed into a use of the lambda's capture. This program has defined
behavior and is being miscompiled.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
` (3 preceding siblings ...)
2020-10-02 1:00 ` richard-gccbugzilla at metafoo dot co.uk
@ 2020-10-02 1:04 ` mpolacek at gcc dot gnu.org
2020-10-02 4:50 ` richard-gccbugzilla at metafoo dot co.uk
2020-10-02 13:32 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-02 1:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
Resolution|INVALID |---
Status|RESOLVED |NEW
Last reconfirmed| |2020-10-02
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Re-opening then, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
` (4 preceding siblings ...)
2020-10-02 1:04 ` mpolacek at gcc dot gnu.org
@ 2020-10-02 4:50 ` richard-gccbugzilla at metafoo dot co.uk
2020-10-02 13:32 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: richard-gccbugzilla at metafoo dot co.uk @ 2020-10-02 4:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
--- Comment #6 from Richard Smith <richard-gccbugzilla at metafoo dot co.uk> ---
My apologies, I misread the testcase. Yes, this is UB.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/97256] auto function return different result
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
` (5 preceding siblings ...)
2020-10-02 4:50 ` richard-gccbugzilla at metafoo dot co.uk
@ 2020-10-02 13:32 ` redi at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-02 13:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97256
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And closing again.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-10-02 13:32 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 14:08 [Bug c++/97256] New: auto function return different result tangyixuan at mail dot dlut.edu.cn
2020-09-30 15:00 ` [Bug c++/97256] " rguenth at gcc dot gnu.org
2020-10-01 10:01 ` redi at gcc dot gnu.org
2020-10-01 10:01 ` redi at gcc dot gnu.org
2020-10-02 1:00 ` richard-gccbugzilla at metafoo dot co.uk
2020-10-02 1:04 ` mpolacek at gcc dot gnu.org
2020-10-02 4:50 ` richard-gccbugzilla at metafoo dot co.uk
2020-10-02 13:32 ` redi 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).