https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77591

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2016-09-14
      Known to work|                            |5.4.0
            Summary|decltype(auto) and ternary  |[6/7 Regression]
                   |operator allow returning    |decltype(auto) and ternary
                   |local reference without a   |operator allow returning
                   |warning                     |local reference without a
                   |                            |warning
     Ever confirmed|0                           |1
      Known to fail|                            |6.2.0, 7.0

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That code doesn't compile, because it's incomplete.

class Counter { };

decltype(auto) foo_warn() {
  Counter c;
  return (c);
}

decltype(auto) foo_no_warn() {
  Counter c;
  return 1==1 ? c : c;
}

Additionally, the warning that's missing without -O2 says address not
reference:

f.cc: In function ‘decltype(auto) foo_no_warn()’:
f.cc:10:21: warning: function returns address of local variable
[-Wreturn-local-addr]
   return 1==1 ? c : c;
                     ^

With GCC 5 both warnings say reference and are present without optimization.

Reply via email to