]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: decltype(auto) deduction of statement-expression [PR116418]
authorPatrick Palka <ppalka@redhat.com>
Thu, 12 Sep 2024 16:45:03 +0000 (12:45 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 17 Jun 2025 21:10:04 +0000 (17:10 -0400)
commit2230c7a505d88ac5fa6f85d7da5fb3a2e09a4cba
treeb98c633536f6eb951465a0d97b1832f0ea1d19ff
parent448750aff5b000fbc79183f3ef316d71a6a1701b
c++: decltype(auto) deduction of statement-expression [PR116418]

r8-7538 for PR84968 made strip_typedefs_expr diagnose STATEMENT_LIST
so that we reject statement-expressions in noexcept-specifiers to
match our behavior in template arguments (which the parser diagnoses
directly).

Later r11-7452 made decltype(auto) deduction canonicalize the expression
(as an implementation detail) which in turn calls strip_typedefs_expr,
and so ever since we inadvertently reject decltype(auto) deduction of a
statement-expression.

This patch just removes the diagnostic in strip_typedefs_expr and instead
treats statement-expressions similar to lambda-expressions.  The function
doesn't seem like the right place for such a diagnostic and so it seems
easier to just accept rather than try to reject them in a suitable place.

PR c++/116418

gcc/cp/ChangeLog:

* tree.cc (strip_typedefs_expr) <case STATEMENT_LIST>: Replace
this error path with ...
<case STMT_EXPR>: ... this, returning the original tree.

gcc/testsuite/ChangeLog:

* g++.dg/eh/pr84968.C: No longer expect an ahead of time diagnostic
for the statement-expresssion.  Instantiate the template and expect
an incomplete type error instead.
* g++.dg/ext/stmtexpr26.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
(cherry picked from commit 12bdcc3d7970860b9d66ed4dea203bde8fd68d4d)
gcc/cp/tree.cc
gcc/testsuite/g++.dg/eh/pr84968.C
gcc/testsuite/g++.dg/ext/stmtexpr26.C [new file with mode: 0644]