public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99362] New: invalid unused result
@ 2021-03-03 15:36 gcc at cookiesoft dot de
  2021-03-03 15:52 ` [Bug c++/99362] " jakub at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gcc at cookiesoft dot de @ 2021-03-03 15:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99362
           Summary: invalid unused result
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at cookiesoft dot de
  Target Milestone: ---
            Target: arm

The following code will emit a warning on arm 32 bit compilers:

```
struct S {
    [[nodiscard]] S() {}
};

int main() {
    S s;
}
```

```
<source>: In function 'int main()':
<source>:6:7: warning: ignoring return value of 'S::S()', declared with
attribute 'nodiscard' [-Wunused-result]
    6 |     S s;
      |       ^
<source>:2:19: note: declared here
    2 |     [[nodiscard]] S() {}
      |                   ^
<source>:6:7: warning: ignoring return value of 'S::S()', declared with
attribute 'nodiscard' [-Wunused-result]
    6 |     S s;
      |       ^
<source>:2:19: note: declared here
    2 |     [[nodiscard]] S() {}
      |                   ^
Compiler returned: 0
```

```
S s = {}
```

does not emit such warning.

Does not emit a warning on x86 compiler though.
Does not emit a warning on 9.x branch, seems to be a regression.

Godbolt link: https://godbolt.org/z/4Kof1x

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

* [Bug c++/99362] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
@ 2021-03-03 15:52 ` jakub at gcc dot gnu.org
  2021-03-03 16:28 ` gcc at cookiesoft dot de
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-03 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
[[nodiscard]] on a constructor makes no sense.
The reason it warns on arm is that under the hood the EABI requires ctors to
return this, while on most other arches constructors don't return anything.

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

* [Bug c++/99362] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
  2021-03-03 15:52 ` [Bug c++/99362] " jakub at gcc dot gnu.org
@ 2021-03-03 16:28 ` gcc at cookiesoft dot de
  2021-03-03 17:37 ` harald at gigawatt dot nl
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gcc at cookiesoft dot de @ 2021-03-03 16:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from gcc at cookiesoft dot de ---
it's not my code, but a MCVE ;)

I'm using
[tomlplusplus](https://github.com/marzer/tomlplusplus/blob/master/toml.hpp) and
there the constructor is marked as nodiscard.

I may file an issue there.

So, what about this issue? I guess it's still a bug?!

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

* [Bug c++/99362] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
  2021-03-03 15:52 ` [Bug c++/99362] " jakub at gcc dot gnu.org
  2021-03-03 16:28 ` gcc at cookiesoft dot de
@ 2021-03-03 17:37 ` harald at gigawatt dot nl
  2021-03-03 19:16 ` [Bug c++/99362] [10/11 Regression] " jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: harald at gigawatt dot nl @ 2021-03-03 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #3 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Jakub Jelinek from comment #1)
> [[nodiscard]] on a constructor makes no sense.

[[nodiscard]] on constructors doesn't apply to the implicit return value forced
by some ABIs being discarded, it applies to the constructed type being
discarded, see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1771r1.pdf, and can
make sense if it is used for that.

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

* [Bug c++/99362] [10/11 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (2 preceding siblings ...)
  2021-03-03 17:37 ` harald at gigawatt dot nl
@ 2021-03-03 19:16 ` jakub at gcc dot gnu.org
  2021-03-03 19:44 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-03 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Priority|P3                          |P2
   Last reconfirmed|                            |2021-03-03
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |10.3
            Summary|invalid unused result       |[10/11 Regression] invalid
                   |                            |unused result

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Caused by r10-4001-g8ad0c477e888d34c8fc6dbcc008ef66505071d65
PR88146 fixed this for arm before, but then r10-4001 when implementing P1771R1
readded this for constructors.  It is now needed for ctors too, but needs to
differentiate for them between the cases P1771R1 requires and normal
targetm.cxx.cdtor_returns_this construction.

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

* [Bug c++/99362] [10/11 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (3 preceding siblings ...)
  2021-03-03 19:16 ` [Bug c++/99362] [10/11 Regression] " jakub at gcc dot gnu.org
@ 2021-03-03 19:44 ` jakub at gcc dot gnu.org
  2021-03-04 15:05 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-03 19:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 50295
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50295&action=edit
gcc11-pr99362.patch

Untested fix.

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

* [Bug c++/99362] [10/11 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (4 preceding siblings ...)
  2021-03-03 19:44 ` jakub at gcc dot gnu.org
@ 2021-03-04 15:05 ` cvs-commit at gcc dot gnu.org
  2021-03-04 15:06 ` [Bug c++/99362] [10 " jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-04 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r11-7512-gc9816196328a4f4b927f08cf2f66cf255849da0b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 4 16:04:48 2021 +0100

    c++: Fix up [[nodiscard]] on ctors on targetm.cxx.cdtor_returns_this
targets [PR99362]

    In the P1771R1 changes JeanHeyd reverted part of Alex' PR88146 fix,
    but that seems to be incorrect to me.
    Where P1771R1 suggests warnings for [[nodiscard]] on constructors is
    handled in a different place - in particular the TARGET_EXPR handling
    of convert_to_void.  When we have CALL_EXPR of a ctor, on most arches
    that call has void return type and so returns early, and on arm where
    the ctor returns the this pointer it is undesirable to warn as it warns
    about all ctor calls, not just the ones where it should warn.

    The P1771R1 changes added a test for this, but as it was given *.c
    extension rather than *.C, the test was never run and so this didn't get
    spotted immediately.  The test also had a bug, (?n) can't be used
    in dg-warning/dg-error because those are implemented by prepending
    some regexp before the user provided one and (?n) must come at the start
    of the regexp.  Furthermore, while -ftrack-macro-expansion=0 is useful
    in one nodiscard test which uses macros, I don't see how it would be
    relevant to all the other cpp2a/nodiscard* tests which don't use any
    macros.

    2021-03-04  Jakub Jelinek  <jakub@redhat.com>

            PR c++/88146
            PR c++/99362
    gcc/cp/
            * cvt.c (convert_to_void): Revert 2019-10-17 changes.  Clarify
            comment.
    gcc/testsuite/
            * g++.dg/cpp2a/nodiscard-constructor.c: Renamed to ...
            * g++.dg/cpp2a/nodiscard-constructor1.C: ... this.  Remove
            -ftrack-macro-expansion=0 from dg-options.  Don't use (?n) in
            dg-warning regexps, instead replace .* with \[^\n\r]*.
            * g++.dg/cpp2a/nodiscard-constructor2.C: New test.
            * g++.dg/cpp2a/nodiscard-reason-only-one.C: Remove
            -ftrack-macro-expansion=0 from dg-options.
            * g++.dg/cpp2a/nodiscard-reason-nonstring.C: Likewise.
            * g++.dg/cpp2a/nodiscard-once.C: Likewise.

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

* [Bug c++/99362] [10 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (5 preceding siblings ...)
  2021-03-04 15:05 ` cvs-commit at gcc dot gnu.org
@ 2021-03-04 15:06 ` jakub at gcc dot gnu.org
  2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-04 15:06 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11 Regression] invalid  |[10 Regression] invalid
                   |unused result               |unused result

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed on the trunk so far.

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

* [Bug c++/99362] [10 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (6 preceding siblings ...)
  2021-03-04 15:06 ` [Bug c++/99362] [10 " jakub at gcc dot gnu.org
@ 2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
  2021-03-20  8:09 ` jakub at gcc dot gnu.org
  2021-04-23 12:37 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-03-19 23:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:01edf2031461b558f630afea382a813e41b631e6

commit r10-9481-g01edf2031461b558f630afea382a813e41b631e6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Mar 4 16:04:48 2021 +0100

    c++: Fix up [[nodiscard]] on ctors on targetm.cxx.cdtor_returns_this
targets [PR99362]

    In the P1771R1 changes JeanHeyd reverted part of Alex' PR88146 fix,
    but that seems to be incorrect to me.
    Where P1771R1 suggests warnings for [[nodiscard]] on constructors is
    handled in a different place - in particular the TARGET_EXPR handling
    of convert_to_void.  When we have CALL_EXPR of a ctor, on most arches
    that call has void return type and so returns early, and on arm where
    the ctor returns the this pointer it is undesirable to warn as it warns
    about all ctor calls, not just the ones where it should warn.

    The P1771R1 changes added a test for this, but as it was given *.c
    extension rather than *.C, the test was never run and so this didn't get
    spotted immediately.  The test also had a bug, (?n) can't be used
    in dg-warning/dg-error because those are implemented by prepending
    some regexp before the user provided one and (?n) must come at the start
    of the regexp.  Furthermore, while -ftrack-macro-expansion=0 is useful
    in one nodiscard test which uses macros, I don't see how it would be
    relevant to all the other cpp2a/nodiscard* tests which don't use any
    macros.

    2021-03-04  Jakub Jelinek  <jakub@redhat.com>

            PR c++/88146
            PR c++/99362
    gcc/cp/
            * cvt.c (convert_to_void): Revert 2019-10-17 changes.  Clarify
            comment.
    gcc/testsuite/
            * g++.dg/cpp2a/nodiscard-constructor.c: Renamed to ...
            * g++.dg/cpp2a/nodiscard-constructor1.C: ... this.  Remove
            -ftrack-macro-expansion=0 from dg-options.  Don't use (?n) in
            dg-warning regexps, instead replace .* with \[^\n\r]*.
            * g++.dg/cpp2a/nodiscard-constructor2.C: New test.
            * g++.dg/cpp2a/nodiscard-reason-only-one.C: Remove
            -ftrack-macro-expansion=0 from dg-options.
            * g++.dg/cpp2a/nodiscard-reason-nonstring.C: Likewise.
            * g++.dg/cpp2a/nodiscard-once.C: Likewise.

    (cherry picked from commit c9816196328a4f4b927f08cf2f66cf255849da0b)

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

* [Bug c++/99362] [10 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (7 preceding siblings ...)
  2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
@ 2021-03-20  8:09 ` jakub at gcc dot gnu.org
  2021-04-23 12:37 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-03-20  8:09 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 10.3 too.

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

* [Bug c++/99362] [10 Regression] invalid unused result
  2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
                   ` (8 preceding siblings ...)
  2021-03-20  8:09 ` jakub at gcc dot gnu.org
@ 2021-04-23 12:37 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-23 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |georg.schwab at emocean dot io

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 100210 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-04-23 12:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 15:36 [Bug c++/99362] New: invalid unused result gcc at cookiesoft dot de
2021-03-03 15:52 ` [Bug c++/99362] " jakub at gcc dot gnu.org
2021-03-03 16:28 ` gcc at cookiesoft dot de
2021-03-03 17:37 ` harald at gigawatt dot nl
2021-03-03 19:16 ` [Bug c++/99362] [10/11 Regression] " jakub at gcc dot gnu.org
2021-03-03 19:44 ` jakub at gcc dot gnu.org
2021-03-04 15:05 ` cvs-commit at gcc dot gnu.org
2021-03-04 15:06 ` [Bug c++/99362] [10 " jakub at gcc dot gnu.org
2021-03-19 23:30 ` cvs-commit at gcc dot gnu.org
2021-03-20  8:09 ` jakub at gcc dot gnu.org
2021-04-23 12:37 ` jakub 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).