Index: clang/include/clang/AST/PrettyPrinter.h =================================================================== --- clang/include/clang/AST/PrettyPrinter.h +++ clang/include/clang/AST/PrettyPrinter.h @@ -63,7 +63,8 @@ MSWChar(LO.MicrosoftExt && !LO.WChar), IncludeNewlines(true), MSVCFormatting(false), ConstantsAsWritten(false), SuppressImplicitBase(false), FullyQualifiedName(false), - PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true) {} + GlobalScopeQualifiedName(false), PrintCanonicalTypes(false), + PrintInjectedClassNameWithArguments(true) {} /// Adjust this printing policy for cases where it's known that we're /// printing C++ code (for instance, if AST dumping reaches a C++-only @@ -241,6 +242,13 @@ /// This is the opposite of SuppressScope and thus overrules it. unsigned FullyQualifiedName : 1; + // When true, class and struct types (to be expanded if needed) will be + // prepended with "::" + // Note it also requires `FullyQualifiedName` to also be set to true, as it + // does not make sense to prepend "::" to a non fully-qualified name. + // This targets generated code. + unsigned GlobalScopeQualifiedName : 1; + /// Whether to print types as written or canonically. unsigned PrintCanonicalTypes : 1; Index: clang/lib/AST/TypePrinter.cpp =================================================================== --- clang/lib/AST/TypePrinter.cpp +++ clang/lib/AST/TypePrinter.cpp @@ -19,6 +19,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/PrettyPrinter.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" @@ -40,6 +41,7 @@ #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/raw_ostream.h" #include +#include #include using namespace clang; @@ -320,6 +322,10 @@ HasEmptyPlaceHolder = false; } + if (Policy.FullyQualifiedName && Policy.GlobalScopeQualifiedName && + T->isStructureOrClassType()) { + OS << "::"; + } switch (T->getTypeClass()) { #define ABSTRACT_TYPE(CLASS, PARENT) #define TYPE(CLASS, PARENT) case Type::CLASS: \