]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: simplify handling implicit INDIRECT_REF and co_await in convert_to_void
authorArsen Arsenović <arsen@aarsen.me>
Fri, 20 Sep 2024 11:13:02 +0000 (13:13 +0200)
committerIain Sandoe <iain@sandoe.co.uk>
Mon, 5 May 2025 22:14:07 +0000 (23:14 +0100)
commit0ff545dbc2fd6ffa6ae544c3754ecaa7f9864a22
tree0ca3da6815a70c7093284defa48c94e37d86f7bf
parent694b942a179f5fbaee882a5e619e5bbaf64b4d11
c++: simplify handling implicit INDIRECT_REF and co_await in convert_to_void

convert_to_void has, so far, when converting a co_await expression to
void altered the await_resume expression of a co_await so that it is
also converted to void.  This meant that the type of the await_resume
expression, which is also supposed to be the type of the whole co_await
expression, was not the same as the type of the CO_AWAIT_EXPR tree.

While this has not caused problems so far, it is unexpected, I think.

Also, convert_to_void had a special case when an INDIRECT_REF wrapped a
CALL_EXPR.  In this case, we also diagnosed maybe_warn_nodiscard.  This
was a duplication of logic related to converting call expressions to
void.

Instead, we can generalize a bit, and rather discard the expression that
was implicitly dereferenced instead.

This patch changes the diagnostic of:

  void f(struct S* x) { static_cast<volatile S&>(*x); }

... from:

  warning: indirection will not access object of incomplete type
           'volatile S' in statement

... to:

  warning: implicit dereference will not access object of type
           ‘volatile S’ in statement

... but should have no impact in other cases.

gcc/cp/ChangeLog:

* coroutines.cc (co_await_get_resume_call): Return a tree
directly, rather than a tree pointer.
* cp-tree.h (co_await_get_resume_call): Adjust signature
accordingly.
* cvt.cc (convert_to_void): Do not alter CO_AWAIT_EXPRs when
discarding them.  Simplify handling implicit INDIRECT_REFs.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/nodiscard-1.C: New test.

(cherry picked from commit de03ef6337b0a368d61c74b790313b4216c7ed6e)
gcc/cp/coroutines.cc
gcc/cp/cp-tree.h
gcc/cp/cvt.cc
gcc/testsuite/g++.dg/coroutines/nodiscard-1.C [new file with mode: 0644]