public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference
@ 2024-08-27 15:36 daklishch at gmail dot com
2024-08-27 15:54 ` [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: daklishch at gmail dot com @ 2024-08-27 15:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116502
Bug ID: 116502
Summary: [15 Regression] -Wunused-result warning is not
supressed if coroutine awaiter returns a reference
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: c++-coroutines
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: daklishch at gmail dot com
CC: arsen at gcc dot gnu.org
Target Milestone: ---
After 2664c1bf83855b79d8c43772e71b87ed4f09c174 (cp+coroutines: teach
convert_to_void to diagnose discarded co_awaits), the following code produces
-Wunused-result warning, while the caller clearly wants to suppress it by
casting the co_await result to void.
```
$ cat ../test.cpp
#include <coroutine>
struct SuspendNever {
bool await_ready() noexcept;
void await_suspend(std::coroutine_handle<>) noexcept;
void await_resume() noexcept;
};
struct Coroutine;
struct PromiseType {
Coroutine get_return_object();
SuspendNever initial_suspend();
SuspendNever final_suspend() noexcept;
void return_void();
};
struct Coroutine {
using promise_type = PromiseType;
};
struct Awaiter {
bool await_ready();
void await_suspend(std::coroutine_handle<>);
[[nodiscard]] int& await_resume();
};
Coroutine foo()
{
(void)co_await Awaiter {};
}
$ ~/gcc-15-trunk/bin/g++ ../test.cpp -c -std=c++20 -fno-exceptions
-Wunused-result -o /dev/null
../test.cpp: In function ‘Coroutine foo()’:
../test.cpp:30:29: warning: ignoring return value of ‘int&
Awaiter::await_resume()’, declared with attribute ‘nodiscard’ [-Wunused-result]
30 | (void)co_await Awaiter {};
| ^
../test.cpp:25:24: note: declared here
25 | [[nodiscard]] int& await_resume();
| ^~~~~~~~~~~~
```
The warning is correctly suppressed unless Awaiter::await_resume returns a
reference.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b
2024-08-27 15:36 [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference daklishch at gmail dot com
@ 2024-08-27 15:54 ` pinskia at gcc dot gnu.org
2024-08-27 17:43 ` arsen at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-08-27 15:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116502
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[15 Regression] |[15 Regression]
|-Wunused-result warning |-Wunused-result warning
|cannot be suppressed if |cannot be suppressed if
|coroutine awaiter returns a |coroutine awaiter returns a
|reference |reference after
| |r15-2318-g2664c1bf83855b
Target Milestone|--- |15.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b
2024-08-27 15:36 [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference daklishch at gmail dot com
2024-08-27 15:54 ` [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b pinskia at gcc dot gnu.org
@ 2024-08-27 17:43 ` arsen at gcc dot gnu.org
2024-08-27 18:06 ` daklishch at gmail dot com
2024-09-02 13:34 ` arsen at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-08-27 17:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116502
Arsen Arsenović <arsen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2024-08-27
--- Comment #1 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
thanks for the report!
candidate patchlet:
modified gcc/cp/coroutines.cc
@@ -3423,7 +3423,14 @@ maybe_promote_temps (tree *stmt, void *d)
to run the initializer.
If the initializer is a conditional expression, we need to collect
and declare any promoted variables nested within it. DTORs for such
- variables must be run conditionally too. */
+ variables must be run conditionally too.
+
+ Since here we're synthetically processing code here, we've already
+ emitted any Wunused-result warnings. Below, however, we call
+ finish_expr_stmt, which will convert its operand to void, and could
+ result in such a diagnostic being emitted. To avoid that, convert to
+ void ahead of time.
+ */
if (t->var)
{
tree var = t->var;
@@ -3433,7 +3440,7 @@ maybe_promote_temps (tree *stmt, void *d)
if (TREE_CODE (t->init) == COND_EXPR)
process_conditional (t, vlist);
else
- finish_expr_stmt (t->init);
+ finish_expr_stmt (build1 (CONVERT_EXPR, void_type_node, t->init));
if (tree cleanup = cxx_maybe_build_cleanup (var,
tf_warning_or_error))
{
tree cl = build_stmt (sloc, CLEANUP_STMT, expr_list, cleanup,
var);
@@ -3452,7 +3459,7 @@ maybe_promote_temps (tree *stmt, void *d)
if (TREE_CODE (t->init) == COND_EXPR)
process_conditional (t, vlist);
else
- finish_expr_stmt (t->init);
+ finish_expr_stmt (build1 (CONVERT_EXPR, void_type_node, t->init));
if (expr_list)
{
if (TREE_CODE (expr_list) != STATEMENT_LIST)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b
2024-08-27 15:36 [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference daklishch at gmail dot com
2024-08-27 15:54 ` [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b pinskia at gcc dot gnu.org
2024-08-27 17:43 ` arsen at gcc dot gnu.org
@ 2024-08-27 18:06 ` daklishch at gmail dot com
2024-09-02 13:34 ` arsen at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: daklishch at gmail dot com @ 2024-08-27 18:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116502
--- Comment #2 from Dan Klishch <daklishch at gmail dot com> ---
Can confirm that the patch fixes both the minified reproducer from the bug
report and also the original reproducer (TestAsyncTestStreams from SerenityOS).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b
2024-08-27 15:36 [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference daklishch at gmail dot com
` (2 preceding siblings ...)
2024-08-27 18:06 ` daklishch at gmail dot com
@ 2024-09-02 13:34 ` arsen at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: arsen at gcc dot gnu.org @ 2024-09-02 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116502
Arsen Arsenović <arsen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |arsen at gcc dot gnu.org
--- Comment #3 from Arsen Arsenović <arsen at gcc dot gnu.org> ---
mine, patch sent a few days ago (still needs some work)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-09-02 13:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-27 15:36 [Bug c++/116502] New: [15 Regression] -Wunused-result warning is not supressed if coroutine awaiter returns a reference daklishch at gmail dot com
2024-08-27 15:54 ` [Bug c++/116502] [15 Regression] -Wunused-result warning cannot be suppressed if coroutine awaiter returns a reference after r15-2318-g2664c1bf83855b pinskia at gcc dot gnu.org
2024-08-27 17:43 ` arsen at gcc dot gnu.org
2024-08-27 18:06 ` daklishch at gmail dot com
2024-09-02 13:34 ` arsen 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).