Skip to content

Commit ab52c7c

Browse files
committed
[clang] implement common-sugar for adjusted member-pointers
This implements a missing case for an adjusted member-pointer in getCommonSugaredType, when that was originally implemented here: #130537 This missing case could otherwise cause a crash, so this is a regression fix. This should fix the crash reported here: #132401 (comment) No release notes, since this regression and the underlying feature were never released.
1 parent e70fe9b commit ab52c7c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14135,7 +14135,6 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1413514135
CANONICAL_TYPE(IncompleteArray)
1413614136
CANONICAL_TYPE(HLSLAttributedResource)
1413714137
CANONICAL_TYPE(LValueReference)
14138-
CANONICAL_TYPE(MemberPointer)
1413914138
CANONICAL_TYPE(ObjCInterface)
1414014139
CANONICAL_TYPE(ObjCObject)
1414114140
CANONICAL_TYPE(ObjCObjectPointer)
@@ -14313,6 +14312,15 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1431314312
return QualType();
1431414313
return Ctx.getUsingType(CD, Ctx.getQualifiedType(Underlying));
1431514314
}
14315+
case Type::MemberPointer: {
14316+
const auto *PX = cast<MemberPointerType>(X),
14317+
*PY = cast<MemberPointerType>(Y);
14318+
CXXRecordDecl *Cls = PX->getMostRecentCXXRecordDecl();
14319+
assert(Cls == PY->getMostRecentCXXRecordDecl());
14320+
return Ctx.getMemberPointerType(
14321+
::getCommonPointeeType(Ctx, PX, PY),
14322+
::getCommonQualifier(Ctx, PX, PY, /*IsSame=*/false), Cls);
14323+
}
1431614324
case Type::CountAttributed: {
1431714325
const auto *DX = cast<CountAttributedType>(X),
1431814326
*DY = cast<CountAttributedType>(Y);

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,19 @@ namespace arrays {
186186
// expected-error@-1 {{lvalue of type 'const volatile volatile B1[1]' (aka 'const volatile volatile int[1]')}}
187187
} // namespace balanced_qualifiers
188188
} // namespace arrays
189+
190+
namespace member_pointers {
191+
template <class T> struct W {
192+
X1 a;
193+
Y1 b;
194+
};
195+
struct W1 : W<X2> {};
196+
struct W2 : W<Y2> {};
197+
198+
N t1 = 0 ? &W<X2>::a : &W<Y2>::b;
199+
// expected-error@-1 {{rvalue of type 'B1 W<B2>::*'}}
200+
201+
// FIXME: adjusted MemberPointer does not preserve qualifier
202+
N t3 = 0 ? &W1::a : &W2::b;
203+
// expected-error@-1 {{rvalue of type 'B1 W<void>::*'}}
204+
} // namespace member_pointers

0 commit comments

Comments
 (0)