Skip to content
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

Add tests for template instantiation #7

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kunaltyagi
Copy link
Member

Required for template heavy library like PCL

Currently fails to detect function template instantiation

@divmadan help please 😄

@diivm
Copy link
Collaborator

diivm commented Oct 25, 2020

File:

template <typename T>
struct AStruct { T value; };

template <typename T>
class AClass { const T privateValue; };

template <class T>
T aFunction(T&& aValue) { return aValue; }

template
struct AStruct<int>;

template
class AClass<char>;

template
bool aFunction<bool>(bool&&);

AST dump:

test.cpp:14:7: warning: class 'AClass<char>' does not declare any constructor to initialize its non-modifiable members
class AClass<char>;
      ^
test.cpp:14:7: note: in instantiation of template class 'AClass<char>' requested here
test.cpp:5:24: note: const member 'privateValue' will never be initialized
class AClass { const T privateValue; };
                       ^
TranslationUnitDecl 0x559b7f467068 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x559b7f467948 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x559b7f467600 '__int128'
|-TypedefDecl 0x559b7f4679b8 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x559b7f467620 'unsigned __int128'
|-TypedefDecl 0x559b7f467d40 <<invalid sloc>> <invalid sloc> implicit __NSConstantString '__NSConstantString_tag'
| `-RecordType 0x559b7f467aa0 '__NSConstantString_tag'
|   `-CXXRecord 0x559b7f467a10 '__NSConstantString_tag'
|-TypedefDecl 0x559b7f467de8 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x559b7f467da0 'char *'
|   `-BuiltinType 0x559b7f467100 'char'
|-TypedefDecl 0x559b7f4a5ce0 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'
| `-ConstantArrayType 0x559b7f4a5c80 '__va_list_tag [1]' 1 
|   `-RecordType 0x559b7f467ed0 '__va_list_tag'
|     `-CXXRecord 0x559b7f467e40 '__va_list_tag'
|-ClassTemplateDecl 0x559b7f4a5ea0 <test.cpp:1:1, line:2:27> col:8 AStruct
| |-TemplateTypeParmDecl 0x559b7f4a5d38 <line:1:11, col:20> col:20 referenced typename depth 0 index 0 T
| |-CXXRecordDecl 0x559b7f4a5e10 <line:2:1, col:27> col:8 struct AStruct definition
| | |-DefinitionData aggregate standard_layout trivially_copyable trivial
| | | |-DefaultConstructor exists trivial needs_implicit
| | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| | | |-MoveConstructor exists simple trivial needs_implicit
| | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| | | |-MoveAssignment exists simple trivial needs_implicit
| | | `-Destructor simple irrelevant trivial needs_implicit
| | |-CXXRecordDecl 0x559b7f4a6108 <col:1, col:8> col:8 implicit struct AStruct
| | `-FieldDecl 0x559b7f4a61a8 <col:18, col:20> col:20 value 'T'
| `-ClassTemplateSpecialization 0x559b7f4a6a78 'AStruct'
|-ClassTemplateDecl 0x559b7f4a6340 <line:4:1, line:5:38> col:7 AClass
| |-TemplateTypeParmDecl 0x559b7f4a6210 <line:4:11, col:20> col:20 referenced typename depth 0 index 0 T
| |-CXXRecordDecl 0x559b7f4a62b0 <line:5:1, col:38> col:7 class AClass definition
| | |-DefinitionData standard_layout trivially_copyable trivial
| | | |-DefaultConstructor exists trivial needs_implicit
| | | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| | | |-MoveConstructor exists simple trivial needs_implicit
| | | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| | | |-MoveAssignment exists trivial needs_implicit
| | | `-Destructor simple irrelevant trivial needs_implicit
| | |-CXXRecordDecl 0x559b7f4a65a8 <col:1, col:7> col:7 implicit class AClass
| | `-FieldDecl 0x559b7f4a6648 <col:16, col:24> col:24 privateValue 'const T'
| `-ClassTemplateSpecialization 0x559b7f4d54a8 'AClass'
|-FunctionTemplateDecl 0x559b7f4a6970 <line:7:1, line:8:42> col:3 aFunction
| |-TemplateTypeParmDecl 0x559b7f4a66b0 <line:7:11, col:17> col:17 referenced class depth 0 index 0 T
| |-FunctionDecl 0x559b7f4a68d0 <line:8:1, col:42> col:3 aFunction 'T (T &&)'
| | |-ParmVarDecl 0x559b7f4a67c0 <col:13, col:17> col:17 referenced aValue 'T &&'
| | `-CompoundStmt 0x559b7f4a6a48 <col:25, col:42>
| |   `-ReturnStmt 0x559b7f4a6a38 <col:27, col:34>
| |     `-DeclRefExpr 0x559b7f4a6a18 <col:34> 'T' lvalue ParmVar 0x559b7f4a67c0 'aValue' 'T &&'
| `-FunctionDecl 0x559b7f4d5bb8 <col:1, col:42> col:3 aFunction 'bool (bool &&)'
|   |-TemplateArgument type 'bool'
|   |-ParmVarDecl 0x559b7f4d5b28 <col:13, col:17> col:17 used aValue 'bool &&'
|   `-CompoundStmt 0x559b7f4d5d00 <col:25, col:42>
|     `-ReturnStmt 0x559b7f4d5cf0 <col:27, col:34>
|       `-ImplicitCastExpr 0x559b7f4d5cd8 <col:34> 'bool':'bool' <LValueToRValue>
|         `-DeclRefExpr 0x559b7f4d5cb8 <col:34> 'bool':'bool' lvalue ParmVar 0x559b7f4d5b28 'aValue' 'bool &&'
|-ClassTemplateSpecializationDecl 0x559b7f4a6a78 <line:10:1, line:11:19> col:8 struct AStruct definition
| |-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal
| | |-DefaultConstructor exists trivial needs_implicit
| | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| | |-MoveConstructor exists simple trivial needs_implicit
| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| | |-MoveAssignment exists simple trivial needs_implicit
| | `-Destructor simple irrelevant trivial needs_implicit
| |-TemplateArgument type 'int'
| |-CXXRecordDecl 0x559b7f4d5358 prev 0x559b7f4a6a78 <line:2:1, col:8> col:8 implicit struct AStruct
| `-FieldDecl 0x559b7f4d5430 <col:18, col:20> col:20 value 'int':'int'
`-ClassTemplateSpecializationDecl 0x559b7f4d54a8 <line:13:1, line:14:18> col:7 class AClass definition
  |-DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
  | |-DefaultConstructor exists trivial needs_implicit
  | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
  | |-MoveConstructor exists simple trivial needs_implicit
  | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
  | |-MoveAssignment exists trivial needs_implicit
  | `-Destructor simple irrelevant trivial needs_implicit
  |-TemplateArgument type 'char'
  |-CXXRecordDecl 0x559b7f4d56b0 prev 0x559b7f4d54a8 <line:5:1, col:7> col:7 implicit class AClass
  `-FieldDecl 0x559b7f4d5780 <col:16, col:24> col:24 privateValue 'const char':'const char'
1 warning generated.

@diivm
Copy link
Collaborator

diivm commented Feb 28, 2021

Let's merge #6 first and then solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants