[ASTImporter] Import the default argument of TemplateTypeParmDecl
authorRaphael Isemann <teemperor@gmail.com>
Thu, 26 Nov 2020 16:02:31 +0000 (17:02 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 26 Nov 2020 17:01:30 +0000 (18:01 +0100)
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching TemplateTypeParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Also updates several LLDB tests that now as intended omit the default template
arguments of several std templates.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92103

16 files changed:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
lldb/test/API/commands/expression/import-std-module/deque-basic/TestDequeFromStdModule.py
lldb/test/API/commands/expression/import-std-module/deque-dbg-info-content/TestDbgInfoContentDequeFromStdModule.py
lldb/test/API/commands/expression/import-std-module/forward_list-dbg-info-content/TestDbgInfoContentForwardListFromStdModule.py
lldb/test/API/commands/expression/import-std-module/forward_list/TestForwardListFromStdModule.py
lldb/test/API/commands/expression/import-std-module/list-dbg-info-content/TestDbgInfoContentListFromStdModule.py
lldb/test/API/commands/expression/import-std-module/list/TestListFromStdModule.py
lldb/test/API/commands/expression/import-std-module/queue/TestQueueFromStdModule.py
lldb/test/API/commands/expression/import-std-module/stack/TestStackFromStdModule.py
lldb/test/API/commands/expression/import-std-module/unique_ptr-dbg-info-content/TestUniquePtrDbgInfoContent.py
lldb/test/API/commands/expression/import-std-module/unique_ptr/TestUniquePtrFromStdModule.py
lldb/test/API/commands/expression/import-std-module/vector-bool/TestVectorBoolFromStdModule.py
lldb/test/API/commands/expression/import-std-module/vector-dbg-info-content/TestDbgInfoContentVectorFromStdModule.py
lldb/test/API/commands/expression/import-std-module/vector-of-vectors/TestVectorOfVectorsFromStdModule.py
lldb/test/API/commands/expression/import-std-module/vector/TestVectorFromStdModule.py

index 8355515..5159682 100644 (file)
@@ -5158,8 +5158,6 @@ ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
   // context. This context will be fixed when the actual template declaration
   // is created.
 
-  // FIXME: Import default argument  and constraint expression.
-
   ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
   if (!BeginLocOrErr)
     return BeginLocOrErr.takeError();
@@ -5206,6 +5204,14 @@ ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
         ToIDC);
   }
 
+  if (D->hasDefaultArgument()) {
+    Expected<TypeSourceInfo *> ToDefaultArgOrErr =
+        import(D->getDefaultArgumentInfo());
+    if (!ToDefaultArgOrErr)
+      return ToDefaultArgOrErr.takeError();
+    ToD->setDefaultArgument(*ToDefaultArgOrErr);
+  }
+
   return ToD;
 }
 
index 33e4b72..5a93a73 100644 (file)
@@ -880,6 +880,25 @@ TEST_P(ImportExpr, DependentSizedArrayType) {
                  has(fieldDecl(hasType(dependentSizedArrayType())))))));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateTypeParmDeclNoDefaultArg) {
+  Decl *FromTU = getTuDecl("template<typename T> struct X {};", Lang_CXX03);
+  auto From = FirstDeclMatcher<TemplateTypeParmDecl>().match(
+      FromTU, templateTypeParmDecl(hasName("T")));
+  TemplateTypeParmDecl *To = Import(From, Lang_CXX03);
+  ASSERT_FALSE(To->hasDefaultArgument());
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, TemplateTypeParmDeclDefaultArg) {
+  Decl *FromTU =
+      getTuDecl("template<typename T = int> struct X {};", Lang_CXX03);
+  auto From = FirstDeclMatcher<TemplateTypeParmDecl>().match(
+      FromTU, templateTypeParmDecl(hasName("T")));
+  TemplateTypeParmDecl *To = Import(From, Lang_CXX03);
+  ASSERT_TRUE(To->hasDefaultArgument());
+  QualType ToArg = To->getDefaultArgument();
+  ASSERT_EQ(ToArg, QualType(To->getASTContext().IntTy));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportBeginLocOfDeclRefExpr) {
   Decl *FromTU =
       getTuDecl("class A { public: static int X; }; void f() { (void)A::X; }",
index 18bd8ae..0eaa50a 100644 (file)
@@ -22,7 +22,7 @@ class TestBasicDeque(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        deque_type = "std::deque<int, std::allocator<int> >"
+        deque_type = "std::deque<int>"
         size_type = deque_type + "::size_type"
         value_type = "std::__deque_base<int, std::allocator<int> >::value_type"
         iterator = deque_type + "::iterator"
index e014f08..5a1f1fc 100644 (file)
@@ -22,7 +22,7 @@ class TestDbgInfoContentDeque(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        deque_type = "std::deque<Foo, std::allocator<Foo> >"
+        deque_type = "std::deque<Foo>"
         size_type = deque_type + "::size_type"
         value_type = "std::__deque_base<Foo, std::allocator<Foo> >::value_type"
 
index 704cbc8..b1f206d 100644 (file)
@@ -22,7 +22,7 @@ class TestDbgInfoContentForwardList(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::forward_list<Foo, std::allocator<Foo> >"
+        list_type = "std::forward_list<Foo>"
         value_type = list_type + "::value_type"
 
         # FIXME: This has three elements in it but the formatter seems to
index 12d9a99..9c4bf83 100644 (file)
@@ -22,7 +22,7 @@ class TestBasicForwardList(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::forward_list<int, std::allocator<int> >"
+        list_type = "std::forward_list<int>"
         value_type = list_type + "::value_type"
 
         # FIXME: This has three elements in it but the formatter seems to
index fea6caa..94d9ca7 100644 (file)
@@ -23,7 +23,7 @@ class TestDbgInfoContentList(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::list<Foo, std::allocator<Foo> >"
+        list_type = "std::list<Foo>"
         size_type = list_type + "::size_type"
         value_type = list_type + "::value_type"
 
index 9382c80..0d7d915 100644 (file)
@@ -22,7 +22,7 @@ class TestBasicList(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        list_type = "std::list<int, std::allocator<int> >"
+        list_type = "std::list<int>"
         size_type = list_type + "::size_type"
         value_type = list_type + "::value_type"
 
index 75cc98c..06f77ba 100644 (file)
@@ -22,7 +22,7 @@ class TestQueue(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        queue_type = "std::queue<C, std::deque<C, std::allocator<C> > >"
+        queue_type = "std::queue<C>"
         size_type = queue_type + "::size_type"
         value_type = "std::__deque_base<C, std::allocator<C> >::value_type"
 
@@ -54,9 +54,9 @@ class TestQueue(TestBase):
                          result_value="5")
 
         # Test std::queue functionality with a std::list.
-        queue_type = "std::queue<C, std::list<C, std::allocator<C> > >"
+        queue_type = "std::queue<C, std::list<C> >"
         size_type = queue_type + "::size_type"
-        value_type = "std::list<C, std::allocator<C> >::value_type"
+        value_type = "std::list<C>::value_type"
         self.expect_expr(
             "q_list",
             result_type=queue_type,
index d9a7e18..4486768 100644 (file)
@@ -22,7 +22,7 @@ class TestStack(TestBase):
         self.runCmd("settings set target.import-std-module true")
 
         # Test std::stack functionality with a std::deque.
-        stack_type = "std::stack<C, std::deque<C, std::allocator<C> > >"
+        stack_type = "std::stack<C>"
         size_type = stack_type + "::size_type"
 
         self.expect_expr("s_deque", result_type=stack_type)
@@ -40,7 +40,7 @@ class TestStack(TestBase):
                          result_value="5")
 
         # Test std::stack functionality with a std::vector.
-        stack_type = "std::stack<C, std::vector<C, std::allocator<C> > >"
+        stack_type = "std::stack<C, std::vector<C> >"
         size_type = stack_type + "::size_type"
 
         self.expect_expr("s_vector", result_type=stack_type)
@@ -58,7 +58,7 @@ class TestStack(TestBase):
                          result_value="5")
 
         # Test std::stack functionality with a std::list.
-        stack_type = "std::stack<C, std::list<C, std::allocator<C> > >"
+        stack_type = "std::stack<C, std::list<C> >"
         size_type = stack_type + "::size_type"
         self.expect_expr("s_list", result_type=stack_type)
         self.expect("expr s_list.pop()")
index 9f698af..abc9c19 100644 (file)
@@ -25,7 +25,7 @@ class TestUniquePtrDbgInfoContent(TestBase):
 
         self.expect_expr(
             "s",
-            result_type="std::unique_ptr<Foo, std::default_delete<Foo> >",
+            result_type="std::unique_ptr<Foo>",
             result_children=[ValueCheck(children=[ValueCheck(value="3")])])
         self.expect_expr("s->a", result_type="int", result_value="3")
         self.expect_expr("s->a = 5", result_type="int", result_value="5")
index a3761ad..878315b 100644 (file)
@@ -25,7 +25,7 @@ class TestUniquePtr(TestBase):
 
         self.expect_expr(
             "s",
-            result_type="std::unique_ptr<int, std::default_delete<int> >",
+            result_type="std::unique_ptr<int>",
             result_summary="3",
             result_children=[ValueCheck(name="__value_")])
         self.expect_expr("*s", result_type="int", result_value="3")
index 0f0279e..79e7478 100644 (file)
@@ -20,7 +20,7 @@ class TestBoolVector(TestBase):
                                           "// Set break point at this line.",
                                           lldb.SBFileSpec("main.cpp"))
 
-        vector_type = "std::vector<bool, std::allocator<bool> >"
+        vector_type = "std::vector<bool>"
         size_type = vector_type + "::size_type"
 
         self.runCmd("settings set target.import-std-module true")
index 6537178..d53a9bf 100644 (file)
@@ -23,7 +23,7 @@ class TestDbgInfoContentVector(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        vector_type = "std::vector<Foo, std::allocator<Foo> >"
+        vector_type = "std::vector<Foo>"
         size_type = vector_type + "::size_type"
         value_type = vector_type + "::value_type"
         iterator = vector_type + "::iterator"
index bb1d736..e0b511c 100644 (file)
@@ -20,13 +20,9 @@ class TestVectorOfVectors(TestBase):
                                           "// Set break point at this line.",
                                           lldb.SBFileSpec("main.cpp"))
 
-        vector_type = "std::vector<int, std::allocator<int> >"
-        vector_of_vector_type = "std::vector<" + vector_type + \
-            ", std::allocator<std::vector<int, std::allocator<int> > > >"
-        size_type = (
-            "std::vector<std::vector<int, std::allocator<int> >, " +
-            "std::allocator<std::vector<int, std::allocator<int> > >" +
-            " >::size_type")
+        vector_type = "std::vector<int>"
+        vector_of_vector_type = "std::vector<" + vector_type + " >"
+        size_type = vector_of_vector_type + "::size_type"
         value_type = "std::__vector_base<int, std::allocator<int> >::value_type"
 
         self.runCmd("settings set target.import-std-module true")
@@ -35,13 +31,13 @@ class TestVectorOfVectors(TestBase):
             "a",
             result_type=vector_of_vector_type,
             result_children=[
-                ValueCheck(type="std::vector<int, std::allocator<int> >",
+                ValueCheck(type="std::vector<int>",
                            children=[
                                ValueCheck(value='1'),
                                ValueCheck(value='2'),
                                ValueCheck(value='3'),
                            ]),
-                ValueCheck(type="std::vector<int, std::allocator<int> >",
+                ValueCheck(type="std::vector<int>",
                            children=[
                                ValueCheck(value='3'),
                                ValueCheck(value='2'),
index c9e1c94..9a186e7 100644 (file)
@@ -22,7 +22,7 @@ class TestBasicVector(TestBase):
 
         self.runCmd("settings set target.import-std-module true")
 
-        vector_type = "std::vector<int, std::allocator<int> >"
+        vector_type = "std::vector<int>"
         size_type = vector_type + "::size_type"
         value_type = "std::__vector_base<int, std::allocator<int> >::value_type"
         iterator = vector_type + "::iterator"