[clang] [clang-tools-extra] [clang] [Sema] Preserve nested name specifier prefix in MemberPointerType (PR #118236)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 1 20:09:46 PST 2024


================
@@ -5347,13 +5347,16 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
 
         case NestedNameSpecifier::TypeSpec:
         case NestedNameSpecifier::TypeSpecWithTemplate:
-          ClsType = QualType(NNS->getAsType(), 0);
+          const Type *NNSType = NNS->getAsType();
+          ClsType = QualType(NNSType, 0);
           // Note: if the NNS has a prefix and ClsType is a nondependent
-          // TemplateSpecializationType, then the NNS prefix is NOT included
-          // in ClsType; hence we wrap ClsType into an ElaboratedType.
-          // NOTE: in particular, no wrap occurs if ClsType already is an
-          // Elaborated, DependentName, or DependentTemplateSpecialization.
-          if (isa<TemplateSpecializationType>(NNS->getAsType()))
+          // TemplateSpecializationType or a RecordType, then the NNS prefix is
+          // NOT included in ClsType; hence we wrap ClsType into an
+          // ElaboratedType. NOTE: in particular, no wrap occurs if ClsType
+          // already is an Elaborated, DependentName, or
+          // DependentTemplateSpecialization.
+          if (isa<TemplateSpecializationType>(NNSType) ||
+              (NNSPrefix && isa<RecordType>(NNSType)))
----------------
HighCommander4 wrote:

> We use an ElaboratedType with null prefix to represent a type which was written without qualifiers, so it seems arbitrary to not add the elaboration in this case.

Wrapping RecordTypes into ElaboratedTypes with a null prefix was causing a bunch of failures on the first draft of the patch.

For example, on this line:

https://github.com/llvm/llvm-project/blob/8cb44859cc31929521c09fc6a8add66d53db44de/clang/test/CXX/conv/conv.mem/p4.cpp#L22

the change has the effect of changing the way the derived type is printed from `test1::Derived` to just `Derived`, I guess because when the diagnostic formatter encounters an `ElaboratedType` it says "I know how the type was printed in the source, I will print it the same way in the diagnostic".

Should we accept changes like this to diagnostic output?

https://github.com/llvm/llvm-project/pull/118236


More information about the cfe-commits mailing list