Skip to content

Commit 675aec8

Browse files
[clang] [Sema] Preserve nested name specifier prefix in MemberPointerType
1 parent d77cab8 commit 675aec8

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,13 @@ sizeof...($TemplateParameter[[Elements]]);
10921092
$Field_dependentName[[waldo]];
10931093
}
10941094
};
1095+
)cpp",
1096+
// Pointer-to-member with nested-name-specifiers
1097+
R"cpp(
1098+
struct $Class_def[[Outer]] {
1099+
struct $Class_def[[Inner]] {};
1100+
};
1101+
using $Typedef_decl[[Alias]] = void ($Class[[Outer]]::$Class[[Inner]]:: *)();
10951102
)cpp"};
10961103
for (const auto &TestCase : TestCases)
10971104
// Mask off scope modifiers to keep the tests manageable.

clang/lib/Sema/SemaType.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5347,15 +5347,18 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
53475347

53485348
case NestedNameSpecifier::TypeSpec:
53495349
case NestedNameSpecifier::TypeSpecWithTemplate:
5350-
ClsType = QualType(NNS->getAsType(), 0);
5351-
// Note: if the NNS has a prefix and ClsType is a nondependent
5352-
// TemplateSpecializationType, then the NNS prefix is NOT included
5353-
// in ClsType; hence we wrap ClsType into an ElaboratedType.
5354-
// NOTE: in particular, no wrap occurs if ClsType already is an
5355-
// Elaborated, DependentName, or DependentTemplateSpecialization.
5356-
if (isa<TemplateSpecializationType>(NNS->getAsType()))
5350+
const Type *NNSType = NNS->getAsType();
5351+
ClsType = QualType(NNSType, 0);
5352+
// If ClsType is an Elaborated, DependentName, or
5353+
// DependentTemplateSpecialization, it already stores the NNS prefix.
5354+
// Otherwise, wrap it in an Elaborated type to have a place to store
5355+
// the NNS prefix.
5356+
if (!(isa<ElaboratedType>(NNSType) ||
5357+
isa<DependentNameType>(NNSType) ||
5358+
isa<DependentTemplateSpecializationType>(NNSType))) {
53575359
ClsType = Context.getElaboratedType(ElaboratedTypeKeyword::None,
53585360
NNSPrefix, ClsType);
5361+
}
53595362
break;
53605363
}
53615364
} else {

0 commit comments

Comments
 (0)