[PATCH] D53693: [ASTImporter] Typedef import brings in the complete type

Gabor Marton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 28 13:53:36 PST 2018


martong marked an inline comment as done.
martong added inline comments.


================
Comment at: cfe/trunk/unittests/AST/ASTImporterTest.cpp:3780
+      typedefNameDecl(hasName("U")));
+  ASSERT_TRUE(ToD->getUnderlyingType()->isIncompleteType());
+
----------------
shafik wrote:
> As far as I can tell `S<int>` is complete in `Code`, am I missing something? 
No, `S<int>` is incomplete at this point. The specialization is indeed created, but its type is incomplete. There is no need for the type to be complete because there is not any operation which would require the size of the type.
This is how the AST looks like:
```
|-ClassTemplateDecl 0x1f5b378 <output.cc:2:7, line:5:7> line:3:14 S
| |-TemplateTypeParmDecl 0x1f5b228 <line:2:17, col:26> col:26 typename depth 0 index 0 T
| |-CXXRecordDecl 0x1f5b2e0 <line:3:7, line:5:7> line:3:14 struct S definition
| | |-DefinitionData empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
| | | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
| | | |-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 0x1f5b5e0 <col:7, col:14> col:14 implicit struct S
| | `-CXXMethodDecl 0x1f5b700 <line:4:9, col:18> col:14 foo 'void ()'
| `-ClassTemplateSpecializationDecl 0x1f5b7d8 <line:2:7, line:5:7> line:3:14 struct S
|   `-TemplateArgument type 'int'
`-TypeAliasDecl 0x1f5b988 <line:6:7, col:22> col:13 U 'S<int>':'S<int>'
  `-TemplateSpecializationType 0x1f5b8e0 'S<int>' sugar S
    |-TemplateArgument type 'int'
    `-RecordType 0x1f5b8c0 'S<int>'
      `-ClassTemplateSpecialization 0x1f5b7d8 'S'
```

However, below by using the member access operator (`->`) we require the completion of the type. Alas, the specialization has a definition there, not just a fwd declaration.
The AST of `FromTU` looks like this:
```
|-ClassTemplateDecl 0x2033c28 <input.cc:2:7, line:5:7> line:3:14 S
| |-TemplateTypeParmDecl 0x2033ad8 <line:2:17, col:26> col:26 typename depth 0 index 0 T
| |-CXXRecordDecl 0x2033b90 <line:3:7, line:5:7> line:3:14 struct S definition
| | |-DefinitionData empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
| | | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
| | | |-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 0x2033e90 <col:7, col:14> col:14 implicit struct S
| | `-CXXMethodDecl 0x2033fb0 <line:4:9, col:18> col:14 foo 'void ()'
| `-ClassTemplateSpecializationDecl 0x2034088 <line:2:7, line:5:7> line:3:14 struct S definition
|   |-DefinitionData pass_in_registers empty aggregate standard_layout trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor can_const_default_init
|   | |-DefaultConstructor exists trivial constexpr needs_implicit defaulted_is_constexpr
|   | |-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 0x2034598 prev 0x2034088 <col:7, col:14> col:14 implicit struct S
|   `-CXXMethodDecl 0x2034630 <line:4:9, col:18> col:14 used foo 'void ()'
|-TypeAliasDecl 0x2034238 <line:6:7, col:22> col:13 referenced U 'S<int>':'S<int>'
| `-TemplateSpecializationType 0x2034190 'S<int>' sugar S
|   |-TemplateArgument type 'int'
|   `-RecordType 0x2034170 'S<int>'
|     `-ClassTemplateSpecialization 0x2034088 'S'
`-FunctionDecl 0x2034420 <line:8:7, line:10:7> line:8:12 foo 'void (U *)'
  |-ParmVarDecl 0x2034318 <col:16, col:19> col:19 used u 'U *'
  `-CompoundStmt 0x2061a38 <col:22, line:10:7>
    `-CXXMemberCallExpr 0x2061a10 <line:9:9, col:16> 'void'
      `-MemberExpr 0x2034718 <col:9, col:12> '<bound member function type>' ->foo 0x2034630
        `-ImplicitCastExpr 0x2034700 <col:9> 'U *' <LValueToRValue>
          `-DeclRefExpr 0x2034508 <col:9> 'U *' lvalue ParmVar 0x2034318 'u' 'U *'
```


Repository:
  rL LLVM

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

https://reviews.llvm.org/D53693





More information about the llvm-commits mailing list