Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp =================================================================== --- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp +++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp @@ -1998,6 +1998,18 @@ // and libstdc++ are differentiated by their inline namespaces). printing_policy.SuppressInlineNamespace = false; printing_policy.SuppressUnwrittenScope = false; + // Default arguments are also always important for type formatters. Otherwise + // we would need to always specify two type names for the setups where we do + // know the default arguments and where we don't know default arguments. + // + // For example, without this we would need to have formatters for both: + // std::basic_string + // and + // std::basic_string, std::allocator > + // to support setups where LLDB was able to reconstruct default arguments + // (and we then would have suppressed them from the type name) and also setups + // where LLDB wasn't able to reconstruct the default arguments. + printing_policy.SuppressDefaultTemplateArgs = false; return printing_policy; } Index: lldb/test/API/lang/cpp/default-template-args/Makefile =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/default-template-args/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules Index: lldb/test/API/lang/cpp/default-template-args/TestDefaultTemplateArgs.py =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/default-template-args/TestDefaultTemplateArgs.py @@ -0,0 +1,41 @@ +""" +Test default template arguments. +""" + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @no_debug_info_test + def test(self): + self.build() + lldbutil.run_to_source_breakpoint(self, "// break here", lldb.SBFileSpec("main.cpp")) + + # Declare a template with a template argument that has a default argument. + self.expect("expr --top-level -- template struct $X { int v; };") + + # The type we display to the user should omit the argument with the default + # value. + result = self.expect_expr("$X<> x; x", result_type="$X<>") + # The internal name should also always show all arguments (even if they + # have their default value). + self.assertEqual(result.GetTypeName(), "$X") + + # Test the template but this time specify a non-default value for the + # template argument. + # Both internal type name and the one we display to the user should + # show the non-default value in the type name. + result = self.expect_expr("$X x; x", result_type="$X") + self.assertEqual(result.GetTypeName(), "$X") + + # Test that the formatters are using the internal type names that + # always include all template arguments. + self.expect("type summary add '$X' --summary-string 'summary1'") + self.expect_expr("$X<> x; x", result_summary="summary1") + self.expect("type summary add '$X' --summary-string 'summary2'") + self.expect_expr("$X x; x", result_summary="summary2") Index: lldb/test/API/lang/cpp/default-template-args/main.cpp =================================================================== --- /dev/null +++ lldb/test/API/lang/cpp/default-template-args/main.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; // break here +}