public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
@ 2020-11-26 17:09 egor_suvorov at mail dot ru
  2020-11-26 17:17 ` [Bug c++/98019] " egor_suvorov at mail dot ru
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: egor_suvorov at mail dot ru @ 2020-11-26 17:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98019
           Summary: Concepts: compound requirement expression from
                    'requires' expression is considered discarded-value
                    expression for [[nodiscard]], false positive warning
                    emitted
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: egor_suvorov at mail dot ru
  Target Milestone: ---

The following code:

#include <concepts>
[[nodiscard]] int foo() {
    return 0;
}
[[maybe_unused]] constexpr bool b = requires {
    { foo() } -> std::same_as<int>;
};
[[maybe_unused]] constexpr auto x = sizeof(foo());

gets the following warning at gcc trunk and gcc 10.2 with `-std=c++20`:

<source>:6:10: warning: ignoring return value of 'int foo()', declared with
attribute 'nodiscard' [-Wunused-result]
    6 |     { foo() } -> std::same_as<int>;
      |       ~~~^~
<source>:2:19: note: declared here
    2 | [[nodiscard]] int foo() {
      |                   ^~~

However, `foo()` here is an non-evaluated expression, not a statement which
discards the value. It's highlighted by the use of optional
return-type-requirement. Even if it was not there, I would still not consider
this a warning-worthy.

Note that usage of `foo()` inside `sizeof()` (another non-evaluated context)
does not emit the same warning.

Corresponding Godbolt link: https://godbolt.org/z/aKx3hz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
@ 2020-11-26 17:17 ` egor_suvorov at mail dot ru
  2020-12-03 18:57 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: egor_suvorov at mail dot ru @ 2020-11-26 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Egor Suvorov <egor_suvorov at mail dot ru> ---
Also, I would expect a warning in this case:

requires {
    foo();  // Looks like a statement.
};

but not this:

requires {
    static_cast<void>(foo());
};

or this:

requires {
    { foo() };  // expression check without return type requirements
};

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
  2020-11-26 17:17 ` [Bug c++/98019] " egor_suvorov at mail dot ru
@ 2020-12-03 18:57 ` cvs-commit at gcc dot gnu.org
  2020-12-03 18:57 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-03 18:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:5ea36d20c352a3ca436aa764404f6210b090866b

commit r11-5719-g5ea36d20c352a3ca436aa764404f6210b090866b
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 3 13:55:51 2020 -0500

    c++: Add testcase for PR98019

    This has already been fixed on trunk, but I don't see a testcase for it.

    gcc/testsuite/ChangeLog:

            PR c++/98019
            * g++.dg/cpp2a/concepts-nodiscard1.C: New test.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
  2020-11-26 17:17 ` [Bug c++/98019] " egor_suvorov at mail dot ru
  2020-12-03 18:57 ` cvs-commit at gcc dot gnu.org
@ 2020-12-03 18:57 ` jason at gcc dot gnu.org
  2020-12-03 22:51 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2020-12-03 18:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 11.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
                   ` (2 preceding siblings ...)
  2020-12-03 18:57 ` jason at gcc dot gnu.org
@ 2020-12-03 22:51 ` jason at gcc dot gnu.org
  2020-12-09  5:36 ` cvs-commit at gcc dot gnu.org
  2020-12-09 13:42 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2020-12-03 22:51 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
         Resolution|FIXED                       |---
   Last reconfirmed|                            |2020-12-03

--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Oops, not actually fixed yet, it was only working for me because of another WIP
patch in my tree.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
                   ` (3 preceding siblings ...)
  2020-12-03 22:51 ` jason at gcc dot gnu.org
@ 2020-12-09  5:36 ` cvs-commit at gcc dot gnu.org
  2020-12-09 13:42 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-09  5:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:c3a63fb3854392af65a191154e3586e7f5a1066e

commit r11-5873-gc3a63fb3854392af65a191154e3586e7f5a1066e
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Dec 8 21:47:11 2020 -0500

    c++: Avoid [[nodiscard]] warning in requires-expr [PR98019]

    If we aren't really evaluating the expression, it doesn't matter that the
    return value is discarded.

    gcc/cp/ChangeLog:

            PR c++/98019
            * cvt.c (maybe_warn_nodiscard): Check
c_inhibit_evaluation_warnings.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-nodiscard1.C: Remove xfail.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/98019] Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted
  2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
                   ` (4 preceding siblings ...)
  2020-12-09  5:36 ` cvs-commit at gcc dot gnu.org
@ 2020-12-09 13:42 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2020-12-09 13:42 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Now fixed for GCC 11.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-12-09 13:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 17:09 [Bug d/98019] New: Concepts: compound requirement expression from 'requires' expression is considered discarded-value expression for [[nodiscard]], false positive warning emitted egor_suvorov at mail dot ru
2020-11-26 17:17 ` [Bug c++/98019] " egor_suvorov at mail dot ru
2020-12-03 18:57 ` cvs-commit at gcc dot gnu.org
2020-12-03 18:57 ` jason at gcc dot gnu.org
2020-12-03 22:51 ` jason at gcc dot gnu.org
2020-12-09  5:36 ` cvs-commit at gcc dot gnu.org
2020-12-09 13:42 ` jason 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).