-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] Fix crash when inheriting from a cv-qualified type #70594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang Author: Rajveer Singh Bharadwaj (Rajveer100) ChangesResolves Issue #35603 This change makes the Full diff: https://github.com/llvm/llvm-project/pull/70594.diff 2 Files Affected:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5947805f9576ff8..07f0a12385b46e9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -6431,7 +6431,7 @@ static bool HandleConstructorCall(const Expr *E, const LValue &This,
// Non-virtual base classes are initialized in the order in the class
// definition. We have already checked for virtual base classes.
assert(!BaseIt->isVirtual() && "virtual base for literal type");
- assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
+ assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
"base class initializers not in expected order");
++BaseIt;
#endif
diff --git a/clang/test/Sema/assertion-crash.cpp b/clang/test/Sema/assertion-crash.cpp
new file mode 100644
index 000000000000000..853552108ec2b67
--- /dev/null
+++ b/clang/test/Sema/assertion-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
+
+// expected-no-diagnostics
+
+struct A {};
+using CA = const A;
+
+struct S1 : CA {
+ constexpr S1() : CA() {}
+};
+
+struct S2 : A {
+ constexpr S2() : CA() {}
+};
+
+struct S3 : CA {
+ constexpr S3() : A() {}
+};
|
6c5fda8
to
efea75d
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
The |
LGTM too. Please add a release note though |
@cor3ntin |
You also need to clang-format this patch with git clang-format HEAD~1. |
efea75d
to
1923c21
Compare
@cor3ntin |
1923c21
to
864bd0e
Compare
864bd0e
to
a27a685
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
You might want to include a test from #85256 (comment) |
a27a685
to
f2a9a41
Compare
Resolves Issue llvm#35603 This bug was caused due to the assertions being too strict, loosened by stripping qualifiers from the base class but not from the type of the initializer. Added Release Notes for the same.
f2a9a41
to
caabd75
Compare
@shafik |
I can land this for you after CI passes. |
#85256 can be closed once this PR merged. |
Resolves Issue #35603
This change makes the
assertion
less strict indebug
builds by stripping qualifiers from the base class and ignoring them. I hopeweakened
assertions don't affect other cases where sucherrors
are intended to becaught
by the compiler.