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
// 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();
ToIDC);
}
+ if (D->hasDefaultArgument()) {
+ Expected<TypeSourceInfo *> ToDefaultArgOrErr =
+ import(D->getDefaultArgumentInfo());
+ if (!ToDefaultArgOrErr)
+ return ToDefaultArgOrErr.takeError();
+ ToD->setDefaultArgument(*ToDefaultArgOrErr);
+ }
+
return ToD;
}
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; }",
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"
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"
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
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
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"
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"
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"
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,
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)
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)
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()")
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")
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")
"// 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")
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"
"// 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")
"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'),
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"