Skip to content

Commit e12a1f8

Browse files
authored
[clang] Fix crash when inheriting from a cv-qualified type (#70594)
This change makes the `assertion` less strict in `debug` builds by stripping qualifiers from the base class and ignoring them. I hope `weakened` assertions don't affect other cases where such `errors` are intended to be `caught` by the compiler. Fixes #35603 Fixes #85256
1 parent 6626eab commit e12a1f8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ Bug Fixes to C++ Support
486486
- Fixed a bug that prevented member function templates of class templates declared with a deduced return type
487487
from being explicitly specialized for a given implicit instantiation of the class template.
488488

489+
- Fix crash when inheriting from a cv-qualified type. Fixes:
490+
(`#35603 <https://github.com/llvm/llvm-project/issues/35603>`_)
491+
489492
Bug Fixes to AST Handling
490493
^^^^^^^^^^^^^^^^^^^^^^^^^
491494
- Clang now properly preserves ``FoundDecls`` within a ``ConceptReference``. (#GH82628)

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6456,7 +6456,7 @@ static bool HandleConstructorCall(const Expr *E, const LValue &This,
64566456
// Non-virtual base classes are initialized in the order in the class
64576457
// definition. We have already checked for virtual base classes.
64586458
assert(!BaseIt->isVirtual() && "virtual base for literal type");
6459-
assert(Info.Ctx.hasSameType(BaseIt->getType(), BaseType) &&
6459+
assert(Info.Ctx.hasSameUnqualifiedType(BaseIt->getType(), BaseType) &&
64606460
"base class initializers not in expected order");
64616461
++BaseIt;
64626462
#endif

clang/test/Sema/GH70594.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2+
// RUN: %clang_cc1 -fsyntax-only -std=c++23 %s -verify
3+
4+
// expected-no-diagnostics
5+
6+
struct A {};
7+
using CA = const A;
8+
9+
struct S1 : CA {
10+
constexpr S1() : CA() {}
11+
};
12+
13+
struct S2 : A {
14+
constexpr S2() : CA() {}
15+
};
16+
17+
struct S3 : CA {
18+
constexpr S3() : A() {}
19+
};
20+
21+
struct Int {};
22+
23+
template <class _Hp>
24+
struct __tuple_leaf : _Hp {
25+
constexpr __tuple_leaf() : _Hp() {}
26+
};
27+
28+
constexpr __tuple_leaf<const Int> t;

0 commit comments

Comments
 (0)