[Lldb-commits] [PATCH] D92311: [lldb] Always include template arguments that have their default value in the internal type name

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Nov 30 07:41:22 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0e7bbeb5455: [lldb] Always include template arguments that have their default value in theā€¦ (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92311/new/

https://reviews.llvm.org/D92311

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  lldb/test/API/lang/cpp/default-template-args/Makefile
  lldb/test/API/lang/cpp/default-template-args/TestDefaultTemplateArgs.py
  lldb/test/API/lang/cpp/default-template-args/main.cpp


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
+}
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<typename T = int> 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<int>")
+
+        # 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<long> x; x", result_type="$X<long>")
+        self.assertEqual(result.GetTypeName(), "$X<long>")
+
+        # Test that the formatters are using the internal type names that
+        # always include all template arguments.
+        self.expect("type summary add '$X<int>' --summary-string 'summary1'")
+        self.expect_expr("$X<> x; x", result_summary="summary1")
+        self.expect("type summary add '$X<long>' --summary-string 'summary2'")
+        self.expect_expr("$X<long> x; x", result_summary="summary2")
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/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<char>
+  // and
+  //   std::basic_string<char, std::char_traits<char>, std::allocator<char> >
+  // 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;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92311.308367.patch
Type: text/x-patch
Size: 3735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20201130/848fc723/attachment-0001.bin>


More information about the lldb-commits mailing list