This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77591] New: decltype(auto) and ternary operator allow returning local reference without a warning
- From: "michele.caini at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 14 Sep 2016 14:21:36 +0000
- Subject: [Bug c++/77591] New: decltype(auto) and ternary operator allow returning local reference without a warning
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77591
Bug ID: 77591
Summary: decltype(auto) and ternary operator allow returning
local reference without a warning
Product: gcc
Version: 6.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: michele.caini at gmail dot com
Target Milestone: ---
I'm referring to this question on SO:
http://stackoverflow.com/questions/39490912/decltypeauto-foo-returns-local-reference-without-any-warning
The following code compiles with a warning when compiled with -Wall -O0:
decltype(auto) foo_warn() {
Counter c;
return (c);
}
The code below compiles with no warnings instead:
decltype(auto) foo_no_warn() {
Counter c;
return 1==1 ? c : c;
}
Anyway, a reference to a local variable is returned in both cases.
Using -O2 the warning appears in both cases.