-
Notifications
You must be signed in to change notification settings - Fork 36
Update GetFunctionReturnType API for template functions #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -228,7 +228,7 @@ TEST(FunctionReflectionTest, GetFunctionsUsingName) { | |||||
| } | ||||||
|
|
||||||
| TEST(FunctionReflectionTest, GetFunctionReturnType) { | ||||||
| std::vector<Decl*> Decls, SubDecls; | ||||||
| std::vector<Decl*> Decls, SubDecls, TemplateSubDecls; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'Decls' is not initialized [cppcoreguidelines-init-variables]
Suggested change
|
||||||
| std::string code = R"( | ||||||
| namespace N { class C {}; } | ||||||
| enum Switch { OFF, ON }; | ||||||
|
|
@@ -238,7 +238,6 @@ TEST(FunctionReflectionTest, GetFunctionReturnType) { | |||||
| int f () { return 0; } | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| void f1() {} | ||||||
| double f2() { return 0.2; } | ||||||
| Switch f3() { return ON; } | ||||||
|
|
@@ -248,22 +247,56 @@ TEST(FunctionReflectionTest, GetFunctionReturnType) { | |||||
| volatile N::C f7() { return N::C(); } | ||||||
| const volatile N::C f8() { return N::C(); } | ||||||
| int n; | ||||||
|
|
||||||
| class MyTemplatedMethodClass { | ||||||
| template<class A> | ||||||
| char get_string(A) { | ||||||
| return 'A'; | ||||||
| } | ||||||
|
|
||||||
| template<class A> | ||||||
| void get_size() {} | ||||||
|
|
||||||
| template<class A> | ||||||
| long add_size (int i) { | ||||||
| return sizeof(A) + i; | ||||||
| } | ||||||
| }; | ||||||
| )"; | ||||||
|
|
||||||
| GetAllTopLevelDecls(code, Decls, true); | ||||||
| GetAllSubDecls(Decls[2], SubDecls); | ||||||
| GetAllSubDecls(Decls[12], TemplateSubDecls); | ||||||
|
|
||||||
| // #include <string> | ||||||
|
|
||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[3])), "void"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[4])), "double"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[5])), "Switch"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[4])), | ||||||
| "double"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[5])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 5 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[5])),
^ |
||||||
| "Switch"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[6])), "N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[7])), "N::C *"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[8])), "const N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[9])), "volatile N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[10])), "const volatile N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[11])), "NULL TYPE"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[7])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 7 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[7])),
^ |
||||||
| "N::C *"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[8])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 8 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[8])),
^ |
||||||
| "const N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[9])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 9 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[9])),
^ |
||||||
| "volatile N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[10])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 10 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[10])),
^ |
||||||
| "const volatile N::C"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[11])), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 11 is a magic number; consider replacing it with a named constant [readability-magic-numbers] EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(Decls[11])),
^ |
||||||
| "NULL TYPE"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(SubDecls[1])), "void"); | ||||||
| EXPECT_EQ(Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(SubDecls[2])), "int"); | ||||||
| EXPECT_EQ( | ||||||
| Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(TemplateSubDecls[1])), | ||||||
| "char"); | ||||||
| EXPECT_EQ( | ||||||
| Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(TemplateSubDecls[2])), | ||||||
| "void"); | ||||||
| EXPECT_EQ( | ||||||
| Cpp::GetTypeAsString(Cpp::GetFunctionReturnType(TemplateSubDecls[3])), | ||||||
| "long"); | ||||||
| } | ||||||
|
|
||||||
| TEST(FunctionReflectionTest, GetFunctionNumArgs) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can D be null here? If not we need to drop the _or_null part.