From d44830a1364cf8cb726d59e91298a5b3077a86d9 Mon Sep 17 00:00:00 2001 From: Marek Polacek <polacek@redhat.com> Date: Tue, 18 Jul 2023 16:02:21 -0400 Subject: [PATCH] c++: fix ICE with is_really_empty_class [PR110106] is_really_empty_class is liable to crash when it gets an incomplete or dependent type. Since r11-557, we pass the yet-uninstantiated class type S<0> of the PARM_DECL s to is_really_empty_class -- because of the potential_rvalue_constant_expression -> is_rvalue_constant_expression change in cp_parser_constant_expression. Here we're not parsing a template so we did not check COMPLETE_TYPE_P as we should. It should work to complete the type before checking COMPLETE_TYPE_P. PR c++/110106 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1): Try to complete the type when !processing_template_decl. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept80.C: New test. (cherry picked from commit e36d1994051122fc6e1f8c728fbd109a59e0a822) --- gcc/cp/constexpr.cc | 5 +++-- gcc/testsuite/g++.dg/cpp0x/noexcept80.C | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept80.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 2c5c9d99b34a..f99d55af02dc 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9080,8 +9080,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, if (now && want_rval) { tree type = TREE_TYPE (t); - if ((processing_template_decl && !COMPLETE_TYPE_P (type)) - || dependent_type_p (type) + if (dependent_type_p (type) + || !COMPLETE_TYPE_P (processing_template_decl + ? type : complete_type (type)) || is_really_empty_class (type, /*ignore_vptr*/false)) /* An empty class has no data to read. */ return true; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept80.C b/gcc/testsuite/g++.dg/cpp0x/noexcept80.C new file mode 100644 index 000000000000..3e90af747e2b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept80.C @@ -0,0 +1,12 @@ +// PR c++/110106 +// { dg-do compile { target c++11 } } + +template<int> struct S +{ +}; + +struct G { + G(S<0>); +}; + +void y(S<0> s) noexcept(noexcept(G{s})); -- GitLab