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++/80896] New: [[nodiscard]] is ignored for functions returning references


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

            Bug ID: 80896
           Summary: [[nodiscard]] is ignored for functions returning
                    references
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamsupermouse at mail dot ru
  Target Milestone: ---

Following produces no warnings:

    int x = 42;
    [[nodiscard]] int &func() {return x;}

    int main() {func();}

But removing the `&` brings the warning back. (`warning: ignoring return value
of '…', declared with attribute nodiscard [-Wunused-result]`)

No flags are needed to reproduce. -Wall, -Wextra, -pedantic-errors, or
-std=c++17 change nothing.

  g++ --version
g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 7.1.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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