public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
@ 2020-08-23  5:57 bazhenov.dn at gmail dot com
  2020-08-23  5:59 ` [Bug c++/96749] " bazhenov.dn at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bazhenov.dn at gmail dot com @ 2020-08-23  5:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96749
           Summary: [coroutines] unexpected 'warning: statement has no
                    effect [-Wunused-value]'
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bazhenov.dn at gmail dot com
  Target Milestone: ---

C++ compiler throws unexpected 'statement with no effect' warning at the ending
brace of a coroutine function when it utilizes co_await expression returning
non-void value which is used as an rvalue within operators '+=', '-=', '*=',
etc.

The warning doesn't appear if the co_await expression is used as an rvalue
within simple assignment ('=') to a temporary variable and then the latter used
within '+=' or other operation.

The attached test code is composed to reveal the issue but is not meant to do
any job. The "#if" alternative in the code can be used to show how warning
disappears.
In a case of meaningful code which causes the warning the code works as
expected.

- g++ version:
  g++ (GCC) 11.0.0 20200822 (experimental)
- configure pameters:
  configure --disable-multilib
- system:
  Linux beauty 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
x86_64 x86_64 x86_64 GNU/Linux
- compiler command:
  g++ -std=c++20 -O0 -g -Wall -fcoroutines -o test test.cpp

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
@ 2020-08-23  5:59 ` bazhenov.dn at gmail dot com
  2020-12-04 14:13 ` max at duempel dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: bazhenov.dn at gmail dot com @ 2020-08-23  5:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Dmitry Bazhenov <bazhenov.dn at gmail dot com> ---
Created attachment 49101
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49101&action=edit
statement-has-no-effect.cpp

Code snippet revealing the problem.

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
  2020-08-23  5:59 ` [Bug c++/96749] " bazhenov.dn at gmail dot com
@ 2020-12-04 14:13 ` max at duempel dot org
  2021-03-04 20:38 ` iains at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: max at duempel dot org @ 2020-12-04 14:13 UTC (permalink / raw)
  To: gcc-bugs

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

Max Kellermann <max at duempel dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |max at duempel dot org

--- Comment #2 from Max Kellermann <max at duempel dot org> ---
Created attachment 49681
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49681&action=edit
Another variant of the bug

I confirm this bug with "gcc version 10.2.0 (Debian 10.2.0-19)", and I have
found another variant of it; in my sample source, using a "struct" return type
triggers the warning, but built-in types do not.

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
  2020-08-23  5:59 ` [Bug c++/96749] " bazhenov.dn at gmail dot com
  2020-12-04 14:13 ` max at duempel dot org
@ 2021-03-04 20:38 ` iains at gcc dot gnu.org
  2021-03-12 15:36 ` iains at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-04 20:38 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2021-03-04
   Target Milestone|---                         |10.3

--- Comment #3 from Iain Sandoe <iains at gcc dot gnu.org> ---
thanks for the report

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
                   ` (2 preceding siblings ...)
  2021-03-04 20:38 ` iains at gcc dot gnu.org
@ 2021-03-12 15:36 ` iains at gcc dot gnu.org
  2021-03-15 15:49 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-12 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |iains at gcc dot gnu.org

--- Comment #4 from Iain Sandoe <iains at gcc dot gnu.org> ---
Created attachment 50377
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50377&action=edit
Patch under test

thanks for the reports.

Even though user code cannot, the compiler can generate things like:

(make some temporary, use that temporary)

So a compound statement that builds a temporary that we then use in the second
part.

When this idiom was encountered, the transforms applied to split await
expressions out were producing something like

{
 build temporary
 temporary
 use the temporary
}

so the middle statement was harmless, but also has no effect (hence the
warning).

the patch under test accounts for this idiom.

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
                   ` (3 preceding siblings ...)
  2021-03-12 15:36 ` iains at gcc dot gnu.org
@ 2021-03-15 15:49 ` cvs-commit at gcc dot gnu.org
  2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
  2021-03-24 12:38 ` iains at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-15 15:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>:

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

commit r11-7674-ged8198461735f9b5b3c2cbe50f9913690ce4b4ca
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Tue Mar 2 10:12:58 2021 +0000

    coroutines : Avoid generating empty statements [PR96749].

    In the compiler-only idiom:
    " a = (target expr creats temp, op uses temp) "
    the target expression variable needs to be promoted to a frame one
    (if the expression has a suspend point).  However, the only uses of
    the var are in the second part of the compound expression - and we
    were creating an empty statement corresponding to the (now unused)
    first arm.  This then produces the spurious warnings noted.

    Fixed by avoiding generation of a separate variable nest for
    isolated target expressions (or similarly isolated co_awaits used
    in a function call).

    gcc/cp/ChangeLog:

            PR c++/96749
            * coroutines.cc (flatten_await_stmt): Allow for the case
            where a target expression variable only has uses in the
            second part of a compound expression.
            (maybe_promote_temps): Avoid emiting empty statements.

    gcc/testsuite/ChangeLog:

            PR c++/96749
            * g++.dg/coroutines/pr96749-1.C: New test.
            * g++.dg/coroutines/pr96749-2.C: New test.

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
                   ` (4 preceding siblings ...)
  2021-03-15 15:49 ` cvs-commit at gcc dot gnu.org
@ 2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
  2021-03-24 12:38 ` iains at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-22 22:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Iain D Sandoe
<iains@gcc.gnu.org>:

https://gcc.gnu.org/g:8fba8178ac49493ed7998fb9008810aac8138c19

commit r10-9515-g8fba8178ac49493ed7998fb9008810aac8138c19
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Tue Mar 2 10:12:58 2021 +0000

    coroutines : Avoid generating empty statements [PR96749].

    In the compiler-only idiom:
    " a = (target expr creats temp, op uses temp) "
    the target expression variable needs to be promoted to a frame one
    (if the expression has a suspend point).  However, the only uses of
    the var are in the second part of the compound expression - and we
    were creating an empty statement corresponding to the (now unused)
    first arm.  This then produces the spurious warnings noted.

    Fixed by avoiding generation of a separate variable nest for
    isolated target expressions (or similarly isolated co_awaits used
    in a function call).

    gcc/cp/ChangeLog:

            PR c++/96749
            * coroutines.cc (flatten_await_stmt): Allow for the case
            where a target expression variable only has uses in the
            second part of a compound expression.
            (maybe_promote_temps): Avoid emiting empty statements.

    gcc/testsuite/ChangeLog:

            PR c++/96749
            * g++.dg/coroutines/pr96749-1.C: New test.
            * g++.dg/coroutines/pr96749-2.C: New test.

    (cherry picked from commit ed8198461735f9b5b3c2cbe50f9913690ce4b4ca)

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

* [Bug c++/96749] [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]'
  2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
                   ` (5 preceding siblings ...)
  2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
@ 2021-03-24 12:38 ` iains at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: iains at gcc dot gnu.org @ 2021-03-24 12:38 UTC (permalink / raw)
  To: gcc-bugs

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

Iain Sandoe <iains at gcc dot gnu.org> changed:

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

--- Comment #7 from Iain Sandoe <iains at gcc dot gnu.org> ---
fixed for master and 10.3

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

end of thread, other threads:[~2021-03-24 12:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-23  5:57 [Bug c++/96749] New: [coroutines] unexpected 'warning: statement has no effect [-Wunused-value]' bazhenov.dn at gmail dot com
2020-08-23  5:59 ` [Bug c++/96749] " bazhenov.dn at gmail dot com
2020-12-04 14:13 ` max at duempel dot org
2021-03-04 20:38 ` iains at gcc dot gnu.org
2021-03-12 15:36 ` iains at gcc dot gnu.org
2021-03-15 15:49 ` cvs-commit at gcc dot gnu.org
2021-03-22 22:04 ` cvs-commit at gcc dot gnu.org
2021-03-24 12:38 ` iains 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).