https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110075
Viktor Ostashevskyi <ostash at ostash dot kiev.ua> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ostash at ostash dot kiev.ua
--- Comment #4 from Viktor Ostashevskyi <ostash at ostash dot kiev.ua> ---
I have even simpler reproducer:
---
class X{};
const X x1;
const X x2;
const X& get(const int& i)
{
return i == 0 ? x1 : x2;
}
void foo() {
[[maybe_unused]] const X& x = get(10);
}
---
<source>: In function 'void foo()':
<source>:23:31: warning: possibly dangling reference to a temporary
[-Wdangling-reference]
23 | [[maybe_unused]] const X& x = get(10);
| ^
<source>:23:38: note: the temporary was destroyed at the end of the full
expression 'get(10)'
23 | [[maybe_unused]] const X& x = get(10);
|