public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored
@ 2020-11-04 7:21 pacoarjonilla at yahoo dot es
2020-11-04 14:43 ` [Bug c++/97712] " mpolacek at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: pacoarjonilla at yahoo dot es @ 2020-11-04 7:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712
Bug ID: 97712
Summary: Attribute nodiscard in virtual methods is ignored
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: pacoarjonilla at yahoo dot es
Target Milestone: ---
The standard attribute [[nodiscard]] is ignored if the function is virtual.
Versions GNU C++ trunk and GNU C++ 10.2 fails to issue a warning on the
following snippet:
>>>>>>>>>>>
struct B {
[[nodiscard]] virtual int f() = 0;
};
struct D : public B {
[[nodiscard]] int f() override {return 1;}
};
int main() {
B * b = new D;
b->f(); // GNU C++ does not warn about discarded value
}
<<<<<<<<<<<<<
Clang does issue a warning appropriately.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/97712] Attribute nodiscard in virtual methods is ignored 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es @ 2020-11-04 14:43 ` mpolacek at gcc dot gnu.org 2020-11-04 18:48 ` mpolacek at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: mpolacek at gcc dot gnu.org @ 2020-11-04 14:43 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712 Marek Polacek <mpolacek at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mpolacek at gcc dot gnu.org Last reconfirmed| |2020-11-04 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Confirmed. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/97712] Attribute nodiscard in virtual methods is ignored 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es 2020-11-04 14:43 ` [Bug c++/97712] " mpolacek at gcc dot gnu.org @ 2020-11-04 18:48 ` mpolacek at gcc dot gnu.org 2020-11-04 18:54 ` jakub at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: mpolacek at gcc dot gnu.org @ 2020-11-04 18:48 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712 --- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> --- Looks like we don't track attributes properly for OBJ_TYPE_REFs in maybe_warn_nodiscard. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/97712] Attribute nodiscard in virtual methods is ignored 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es 2020-11-04 14:43 ` [Bug c++/97712] " mpolacek at gcc dot gnu.org 2020-11-04 18:48 ` mpolacek at gcc dot gnu.org @ 2020-11-04 18:54 ` jakub at gcc dot gnu.org 2020-11-15 3:14 ` pacoarjonilla at yahoo dot es 2021-06-02 10:32 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: jakub at gcc dot gnu.org @ 2020-11-04 18:54 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> --- [[nodiscard]] is a function attribute rather than function type attribute, so it really doesn't apply to virtual calls (unless it can be devirtualized early). ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/97712] Attribute nodiscard in virtual methods is ignored 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es ` (2 preceding siblings ...) 2020-11-04 18:54 ` jakub at gcc dot gnu.org @ 2020-11-15 3:14 ` pacoarjonilla at yahoo dot es 2021-06-02 10:32 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: pacoarjonilla at yahoo dot es @ 2020-11-15 3:14 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712 --- Comment #4 from Paco Arjonilla <pacoarjonilla at yahoo dot es> --- (In reply to Jakub Jelinek from comment #3) > [[nodiscard]] is a function attribute rather than function type attribute, > so it really doesn't apply to virtual calls (unless it can be devirtualized > early). Is it a bug in GCC or in the C++ standard? ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/97712] Attribute nodiscard in virtual methods is ignored 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es ` (3 preceding siblings ...) 2020-11-15 3:14 ` pacoarjonilla at yahoo dot es @ 2021-06-02 10:32 ` redi at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: redi at gcc dot gnu.org @ 2021-06-02 10:32 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97712 Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |DUPLICATE Status|NEW |RESOLVED --- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- . *** This bug has been marked as a duplicate of bug 84476 *** ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-02 10:32 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-11-04 7:21 [Bug c++/97712] New: Attribute nodiscard in virtual methods is ignored pacoarjonilla at yahoo dot es 2020-11-04 14:43 ` [Bug c++/97712] " mpolacek at gcc dot gnu.org 2020-11-04 18:48 ` mpolacek at gcc dot gnu.org 2020-11-04 18:54 ` jakub at gcc dot gnu.org 2020-11-15 3:14 ` pacoarjonilla at yahoo dot es 2021-06-02 10:32 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).