@@ -118,7 +118,8 @@ namespace {
118118
119119 void printBefore (QualType T, raw_ostream &OS);
120120 void printAfter (QualType T, raw_ostream &OS);
121- void AppendScope (DeclContext *DC, raw_ostream &OS);
121+ void AppendScope (DeclContext *DC, raw_ostream &OS,
122+ DeclarationName NameInScope);
122123 void printTag (TagDecl *T, raw_ostream &OS);
123124 void printFunctionAfter (const FunctionType::ExtInfo &Info, raw_ostream &OS);
124125#define ABSTRACT_TYPE (CLASS, PARENT )
@@ -1028,7 +1029,7 @@ void TypePrinter::printTypeSpec(NamedDecl *D, raw_ostream &OS) {
10281029 // In C, this will always be empty except when the type
10291030 // being printed is anonymous within other Record.
10301031 if (!Policy.SuppressScope )
1031- AppendScope (D->getDeclContext (), OS);
1032+ AppendScope (D->getDeclContext (), OS, D-> getDeclName () );
10321033
10331034 IdentifierInfo *II = D->getIdentifier ();
10341035 OS << II->getName ();
@@ -1218,20 +1219,34 @@ void TypePrinter::printDependentExtIntAfter(const DependentExtIntType *T,
12181219 raw_ostream &OS) {}
12191220
12201221// / Appends the given scope to the end of a string.
1221- void TypePrinter::AppendScope (DeclContext *DC, raw_ostream &OS) {
1222- if (DC->isTranslationUnit ()) return ;
1223- if (DC->isFunctionOrMethod ()) return ;
1224- AppendScope (DC->getParent (), OS);
1222+ void TypePrinter::AppendScope (DeclContext *DC, raw_ostream &OS,
1223+ DeclarationName NameInScope) {
1224+ if (DC->isTranslationUnit ())
1225+ return ;
1226+
1227+ // FIXME: Consider replacing this with NamedDecl::printNestedNameSpecifier,
1228+ // which can also print names for function and method scopes.
1229+ if (DC->isFunctionOrMethod ())
1230+ return ;
12251231
12261232 if (const auto *NS = dyn_cast<NamespaceDecl>(DC)) {
1227- if (Policy.SuppressUnwrittenScope &&
1228- (NS->isAnonymousNamespace () || NS->isInline ()))
1229- return ;
1233+ if (Policy.SuppressUnwrittenScope && NS->isAnonymousNamespace ())
1234+ return AppendScope (DC->getParent (), OS, NameInScope);
1235+
1236+ // Only suppress an inline namespace if the name has the same lookup
1237+ // results in the enclosing namespace.
1238+ if (Policy.SuppressInlineNamespace && NS->isInline () && NameInScope &&
1239+ DC->getParent ()->lookup (NameInScope).size () ==
1240+ DC->lookup (NameInScope).size ())
1241+ return AppendScope (DC->getParent (), OS, NameInScope);
1242+
1243+ AppendScope (DC->getParent (), OS, NS->getDeclName ());
12301244 if (NS->getIdentifier ())
12311245 OS << NS->getName () << " ::" ;
12321246 else
12331247 OS << " (anonymous namespace)::" ;
12341248 } else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1249+ AppendScope (DC->getParent (), OS, Spec->getDeclName ());
12351250 IncludeStrongLifetimeRAII Strong (Policy);
12361251 OS << Spec->getIdentifier ()->getName ();
12371252 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs ();
@@ -1240,12 +1255,15 @@ void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) {
12401255 Spec->getSpecializedTemplate ()->getTemplateParameters ());
12411256 OS << " ::" ;
12421257 } else if (const auto *Tag = dyn_cast<TagDecl>(DC)) {
1258+ AppendScope (DC->getParent (), OS, Tag->getDeclName ());
12431259 if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl ())
12441260 OS << Typedef->getIdentifier ()->getName () << " ::" ;
12451261 else if (Tag->getIdentifier ())
12461262 OS << Tag->getIdentifier ()->getName () << " ::" ;
12471263 else
12481264 return ;
1265+ } else {
1266+ AppendScope (DC->getParent (), OS, NameInScope);
12491267 }
12501268}
12511269
@@ -1272,7 +1290,7 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) {
12721290 // In C, this will always be empty except when the type
12731291 // being printed is anonymous within other Record.
12741292 if (!Policy.SuppressScope )
1275- AppendScope (D->getDeclContext (), OS);
1293+ AppendScope (D->getDeclContext (), OS, D-> getDeclName () );
12761294
12771295 if (const IdentifierInfo *II = D->getIdentifier ())
12781296 OS << II->getName ();
0 commit comments