]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up check for typeid on polymorphic type before C++20 [PR123347]
authorJakub Jelinek <jakub@redhat.com>
Sat, 3 Jan 2026 11:16:51 +0000 (12:16 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 3 Jan 2026 11:16:51 +0000 (12:16 +0100)
The following testcase ICEs since TYPE_POLYMORPHIC_P macro has been
changed to allow being used only on RECORD_TYPE/UNION_TYPE.
This particular spot wasn't adjusted.

2026-01-03  Jakub Jelinek  <jakub@redhat.com>

PR c++/123347
* constexpr.cc (potential_constant_expression_1): Check for
CLASS_TYPE_P before using TYPE_POLYMORPHIC_P on TREE_TYPE (e).

* g++.dg/cpp1y/pr123347.C: New test.

gcc/cp/constexpr.cc
gcc/testsuite/g++.dg/cpp1y/pr123347.C [new file with mode: 0644]

index 9262da952e1c13fe8ca3962aa3bbc5123443b9fd..4b362b1caba3309735c12b28008049a2da1aa8a5 100644 (file)
@@ -12074,6 +12074,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
            && strict
            && !TYPE_P (e)
            && !type_dependent_expression_p (e)
+           && CLASS_TYPE_P (TREE_TYPE (e))
            && TYPE_POLYMORPHIC_P (TREE_TYPE (e)))
           {
             if (flags & tf_error)
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr123347.C b/gcc/testsuite/g++.dg/cpp1y/pr123347.C
new file mode 100644 (file)
index 0000000..65014d7
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/123347
+// { dg-do compile { target c++14 } }
+
+#include <typeinfo>
+
+int a;
+template <int N>
+const std::type_info &v = typeid (a);