diff --git a/clang/include/clang/AST/PrettyPrinter.h b/clang/include/clang/AST/PrettyPrinter.h --- a/clang/include/clang/AST/PrettyPrinter.h +++ b/clang/include/clang/AST/PrettyPrinter.h @@ -130,6 +130,9 @@ /// Suppresses printing of scope specifiers. unsigned SuppressScope : 1; + /// When SuppressScope is true, do not apply it to template parameters. + unsigned NoSuppressTemplateParamsScope : 1; + /// Suppress printing parts of scope specifiers that are never /// written, e.g., for anonymous namespaces. unsigned SuppressUnwrittenScope : 1; diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp --- a/clang/lib/AST/TypePrinter.cpp +++ b/clang/lib/AST/TypePrinter.cpp @@ -110,6 +110,23 @@ } }; +class NoSuppressTemplateParamsScopeRAII { + PrintingPolicy &Policy; + bool OldSuppressScope; + +public: + explicit NoSuppressTemplateParamsScopeRAII(PrintingPolicy &Policy) + : Policy(Policy) { + OldSuppressScope = Policy.SuppressScope; + if (Policy.NoSuppressTemplateParamsScope) + Policy.SuppressScope = false; + } + + ~NoSuppressTemplateParamsScopeRAII() { + Policy.SuppressScope = OldSuppressScope; + } +}; + class TypePrinter { PrintingPolicy Policy; unsigned Indentation; @@ -1370,6 +1387,7 @@ // If this is a class template specialization, print the template // arguments. if (const auto *Spec = dyn_cast(D)) { + NoSuppressTemplateParamsScopeRAII SuppressScopeRAII(Policy); ArrayRef Args; TypeSourceInfo *TAW = Spec->getTypeAsWritten(); if (!Policy.PrintCanonicalTypes && TAW) { diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp --- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -3792,6 +3792,7 @@ clang::PrintingPolicy printing_policy(GetTypePrintingPolicy()); printing_policy.SuppressScope = BaseOnly; + printing_policy.NoSuppressTemplateParamsScope = BaseOnly; return ConstString(qual_type.getAsString(printing_policy)); } diff --git a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py --- a/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py +++ b/lldb/test/API/lang/cpp/unique-types2/TestUniqueTypes.py @@ -36,6 +36,7 @@ self.expect("image lookup -A -t 'Foo::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) self.expect("image lookup -A -t 'Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect("image lookup -A -t '::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, error=True) + self.expect("image lookup -A -t 'Foo::Nested'", DATA_TYPES_DISPLAYED_CORRECTLY, substrs=["1 match found"]) self.expect_expr("t1", result_type="Foo") self.expect_expr("t1", result_type="Foo") @@ -49,6 +50,7 @@ self.expect_expr("p6", result_type="FooPack") self.expect_expr("p7", result_type="FooPack") self.expect_expr("n1", result_type="Foo::Nested") + self.expect_expr("n2", result_type="Foo::Nested") @skipIf(compiler=no_match("clang")) @skipIf(compiler_version=["<", "15.0"]) diff --git a/lldb/test/API/lang/cpp/unique-types2/main.cpp b/lldb/test/API/lang/cpp/unique-types2/main.cpp --- a/lldb/test/API/lang/cpp/unique-types2/main.cpp +++ b/lldb/test/API/lang/cpp/unique-types2/main.cpp @@ -1,3 +1,7 @@ +namespace ns { +struct Bar {}; +} // namespace ns + template struct Foo { T t; template class Nested { @@ -23,5 +27,6 @@ FooPack p7; Foo::Nested n1; + Foo::Nested n2; // Set breakpoint here }