[Bug c++/89757] accepts returning with reference to temporary in constant expression
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Mar 18 17:53:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89757
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
Blocks| |55004
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
In the test case below with pointers rather than references the first static
assertion also isn't rejected despite being undefined, and despite the
-Wreturn-local-addr. (Clang fails the first assertion because unlike GCC it
doesn't fold the return address to null.)
$ cat t.C && gcc -S -Wall t.C
constexpr int* f (int i)
{
return &i;
}
static_assert (nullptr == f (123));
static_assert (nullptr != f (123));
t.C: In function ‘constexpr int* f(int)’:
t.C:3:10: warning: address of local variable ‘i’ returned [-Wreturn-local-addr]
3 | return &i;
| ^~
t.C:1:23: note: declared here
1 | constexpr int* f (int i)
| ~~~~^
t.C: At global scope:
t.C:7:24: error: static assertion failed
7 | static_assert (nullptr != f (123));
| ~~~~~~~~^~~~~~~~~~
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004
[Bug 55004] [meta-bug] constexpr issues
More information about the Gcc-bugs
mailing list