This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77591] New: decltype(auto) and ternary operator allow returning local reference without a warning


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]