]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Don't ICE in build_class_member_access_expr during error recovery [PR118225]
authorSimon Martin <simon@nasilyan.com>
Tue, 21 Jan 2025 12:31:41 +0000 (13:31 +0100)
committerSimon Martin <simon@nasilyan.com>
Tue, 21 Jan 2025 12:34:02 +0000 (13:34 +0100)
The invalid case in this PR trips on an assertion in
build_class_member_access_expr that build_base_path would never return
an error_mark_node, which is actually incorrect if the object involves a
tree with an error_mark_node DECL_INITIAL, like here.

This patch changes the assert to not fire if an error has been reported.

PR c++/118225

gcc/cp/ChangeLog:

* typeck.cc (build_class_member_access_expr): Let errors that
that have been reported go through.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-ice21.C: New test.

gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C [new file with mode: 0644]

index 3e0d71102abd29f8da703bdad7cb4529292a7752..6b549809243a5ec2a2a4052930dafca94c26ebb7 100644 (file)
@@ -2980,7 +2980,7 @@ build_class_member_access_expr (cp_expr object, tree member,
                                    /*nonnull=*/1, complain);
          /* If we found the base successfully then we should be able
             to convert to it successfully.  */
-         gcc_assert (object != error_mark_node);
+         gcc_assert (object != error_mark_node || seen_error ());
        }
 
       /* If MEMBER is from an anonymous aggregate, we have converted
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C
new file mode 100644 (file)
index 0000000..4627365
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/118225
+// { dg-do "compile" { target c++11} }
+
+struct NoMut1 { int a, b; };
+struct NoMut3 : virtual NoMut1 {
+  constexpr NoMut3(int a, int b) // { dg-error "virtual base" "" { target c++23 } }
+    : NoMut1{a, b}
+  {} // { dg-error "virtual base" }
+};
+void mutable_subobjects() {
+  constexpr NoMut3 nm3 = {1, 2}; // { dg-error "call to non" }
+  struct A {
+    void f() {
+      static_assert(nm3.a == 1, ""); // { dg-error "local variable" }
+    }
+  };
+}