diff options
author | Simon Martin <simon@nasilyan.com> | 2025-01-21 13:31:41 +0100 |
---|---|---|
committer | Simon Martin <simon@nasilyan.com> | 2025-01-21 13:34:02 +0100 |
commit | 4e4c378ac1f923a310fa31be85ed8c0c50e9f5ef (patch) | |
tree | f957e2d3691dd480b2957f9a2bf27ac33d74399b | |
parent | 1dd79f44dfb64b441f3d6c64e7f909d73441bd05 (diff) | |
download | gcc-4e4c378ac1f923a310fa31be85ed8c0c50e9f5ef.zip gcc-4e4c378ac1f923a310fa31be85ed8c0c50e9f5ef.tar.gz gcc-4e4c378ac1f923a310fa31be85ed8c0c50e9f5ef.tar.bz2 |
c++: Don't ICE in build_class_member_access_expr during error recovery [PR118225]
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.
-rw-r--r-- | gcc/cp/typeck.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 3e0d711..6b54980 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -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 index 0000000..4627365 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ice21.C @@ -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" } + } + }; +} |