]> 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)
committerArsen Arsenović <arsen@gcc.gnu.org>
Fri, 27 Sep 2024 11:37:37 +0000 (13:37 +0200)
commitde03ef6337b0a368d61c74b790313b4216c7ed6e
tree5e56f3e15bde60e69338bfc637f1a42c62168b50
parent05e4f07cad1eacf869c10622cae2a9cdee3b6a7a
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.
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]