diff options
author | Patrick Palka <ppalka@redhat.com> | 2024-09-12 12:45:03 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2024-09-12 12:45:03 -0400 |
commit | 12bdcc3d7970860b9d66ed4dea203bde8fd68d4d (patch) | |
tree | 6779cd89cd7f44d7cab419172d48bc9f7697d1ce /gcc | |
parent | 4026d89d623e322920b052f7ac0d940ef267dc0f (diff) | |
download | gcc-12bdcc3d7970860b9d66ed4dea203bde8fd68d4d.zip gcc-12bdcc3d7970860b9d66ed4dea203bde8fd68d4d.tar.gz gcc-12bdcc3d7970860b9d66ed4dea203bde8fd68d4d.tar.bz2 |
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/tree.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/eh/pr84968.C | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/stmtexpr26.C | 10 |
3 files changed, 14 insertions, 5 deletions
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index c3a38de..99088da 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -2009,12 +2009,9 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags) } case LAMBDA_EXPR: + case STMT_EXPR: return t; - case STATEMENT_LIST: - error ("statement-expression in a constant expression"); - return error_mark_node; - default: break; } diff --git a/gcc/testsuite/g++.dg/eh/pr84968.C b/gcc/testsuite/g++.dg/eh/pr84968.C index 23c49f4..a6e2191 100644 --- a/gcc/testsuite/g++.dg/eh/pr84968.C +++ b/gcc/testsuite/g++.dg/eh/pr84968.C @@ -9,7 +9,9 @@ struct S { void a() try { } catch (int () - noexcept (({ union b a; true; }))) // { dg-error "constant" } + noexcept (({ union b a; true; }))) // { dg-error "'b a' has incomplete type" } { } }; + +template void S::a<int>(); // { dg-message "required from here" } diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr26.C b/gcc/testsuite/g++.dg/ext/stmtexpr26.C new file mode 100644 index 0000000..2250df5 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/stmtexpr26.C @@ -0,0 +1,10 @@ +// PR c++/116418 +// { dg-do compile { target c++14 } } +// { dg-options "" } + +void foo (); +template <typename> +void bar () +{ + decltype(auto) v = ({ foo (); 3; }); +} |