[Bug c++/77591] New: decltype(auto) and ternary operator allow returning local reference without a warning
michele.caini at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Sep 14 14:21:00 GMT 2016
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.
More information about the Gcc-bugs
mailing list