This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80896] New: [[nodiscard]] is ignored for functions returning references
- From: "iamsupermouse at mail dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 27 May 2017 12:26:04 +0000
- Subject: [Bug c++/80896] New: [[nodiscard]] is ignored for functions returning references
- Auto-submitted: auto-generated
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.