diff options
author | Matheus Izvekov <mizvekov@gmail.com> | 2021-10-11 19:15:36 +0300 |
---|---|---|
committer | Matheus Izvekov <mizvekov@gmail.com> | 2022-07-13 03:10:09 +0300 |
commit | bdc6974f92304f4ed542241b9b89ba58ba6b20aa (patch) | |
tree | 7ccdfc65560c740a1b6958c14ccd02c36f63fc5e /clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp | |
parent | ee88c0cf09969ba44307068797e12533b94768a6 (diff) |
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.
The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.
An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>
Differential Revision: https://reviews.llvm.org/D112374
Diffstat (limited to 'clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp')
-rw-r--r-- | clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp index 59acc29e8ee9..26d31c669bcc 100644 --- a/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp +++ b/clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp @@ -567,14 +567,12 @@ void ChangeNamespaceTool::run( if (Loc.getTypeLocClass() == TypeLoc::Elaborated) { NestedNameSpecifierLoc NestedNameSpecifier = Loc.castAs<ElaboratedTypeLoc>().getQualifierLoc(); - // This happens for friend declaration of a base class with injected class - // name. - if (!NestedNameSpecifier.getNestedNameSpecifier()) - return; - const Type *SpecifierType = - NestedNameSpecifier.getNestedNameSpecifier()->getAsType(); - if (SpecifierType && SpecifierType->isRecordType()) - return; + // FIXME: avoid changing injected class names. + if (auto *NNS = NestedNameSpecifier.getNestedNameSpecifier()) { + const Type *SpecifierType = NNS->getAsType(); + if (SpecifierType && SpecifierType->isRecordType()) + return; + } } fixTypeLoc(Result, startLocationForType(Loc), endLocationForType(Loc), Loc); } else if (const auto *VarRef = |