[Bug c++/80896] New: [[nodiscard]] is ignored for functions returning references
iamsupermouse at mail dot ru
gcc-bugzilla@gcc.gnu.org
Sat May 27 19:22:00 GMT 2017
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.
More information about the Gcc-bugs
mailing list