<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - template instantiation of classes in class contexts fails for fields with in-class initializers"
href="http://llvm.org/bugs/show_bug.cgi?id=21212">21212</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>template instantiation of classes in class contexts fails for fields with in-class initializers
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider:
struct A {
A();
template <typename T> struct B {
B() {}
int m1 = 0;
};
B<int> m2;
};
A::A() {}
The problem is that we appear to delay the bodies of all inline methods and
member initializers until the closing brace of A's definition, but we force the
instantiation of B<int> before that.
So the AST has a FieldDecl for m1, but it lacks the in-class initializer expr
'0'. We transform m1 in this partially filled in-state, and end up with an
incorrect specialization. Then, once we complete A, we fill in m1's in-class
initializer in the template pattern.
See the AST for supporting evidence:
TranslationUnitDecl 0xd2dda0 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0xd2e070 <<invalid sloc>> <invalid sloc> implicit __int128_t
'__int128'
|-TypedefDecl 0xd2e0b0 <<invalid sloc>> <invalid sloc> implicit __uint128_t
'unsigned __int128'
|-TypedefDecl 0xd2e330 <<invalid sloc>> <invalid sloc> implicit
__builtin_va_list '__va_list_tag [1]'
|-CXXRecordDecl 0xd2e360 <t.cpp:1:1, line:8:1> line:1:8 struct A definition
| |-CXXRecordDecl 0xd2e430 <col:1, col:8> col:8 implicit referenced struct A
| |-CXXConstructorDecl 0xd2e4f0 <line:2:3, col:5> col:3 A 'void (void)'
| |-ClassTemplateDecl 0xd2e650 <line:3:3, line:6:3> line:3:32 B
| | |-TemplateTypeParmDecl 0xd2e570 <col:13, col:22> col:22 typename T
| | |-CXXRecordDecl 0xd2e5f0 <col:25, line:6:3> line:3:32 struct B definition
| | | |-CXXRecordDecl 0xd2e810 <col:25, col:32> col:32 implicit referenced
struct B
| | | |-CXXConstructorDecl 0xd2e8c0 <line:4:5, col:10> col:5 B<T> 'void (void)'
| | | | `-CompoundStmt 0xd72f90 <col:9, col:10>
| | | `-FieldDecl 0xd2e950 <lgetInClassInitializer 1 1 0xd72f70
getInClassInitializer 0 0 0x0
ine:5:5, col:14> col:9 m1 'int'
| | | `-IntegerLiteral 0xd72f70 <col:14> 'int' 0
| | `-ClassTemplateSpecializationDecl 0xd2e990 <line:3:3, line:6:3> line:3:32
struct B definition
| | |-TemplateArgument type 'int'
| | |-CXXRecordDecl 0xd2eb30 prev 0xd2e990 <col:25, col:32> col:32 implicit
struct B
| | |-CXXConstructorDecl 0xd2ebb0 <line:4:5, col:10> col:5 used B 'void
(void)'
| | | `-CompoundStmt 0xd72f90 <col:9, col:10>
| | |-FieldDecl 0xd72ef0 <line:5:5, col:9> col:9 invalid m1 'int'
| | |-CXXConstructorDecl 0xd73020 <line:3:32> col:32 implicit B 'void (const
struct A::B<int> &)' inline noexcept-unevaluated 0xd73020
| | | `-ParmVarDecl 0xd730e0 <col:32> col:32 'const struct A::B<int> &'
| | |-CXXConstructorDecl 0xd73140 <col:32> col:32 implicit B 'void (struct
A::B<int> &&)' inline noexcept-unevaluated 0xd73140
| | | `-ParmVarDecl 0xd73200 <col:32> col:32 'struct A::B<int> &&'
| | `-CXXDestructorDecl 0xd73350 <col:32> col:32 implicit ~B 'void (void)'
inline noexcept-unevaluated 0xd73350getInClassInitializer 0 0 0x0
| |-FieldDecl 0xd72f40 <line:7:3, col:10> col:10 m2 'B<int>':'struct A::B<int>'
| |-CXXConstructorDecl 0xd73240 <line:1:8> col:8 implicit A 'void (const struct
A &)' inline noexcept-unevaluated 0xd73240
| | `-ParmVarDecl 0xd73300 <col:8> col:8 'const struct A &'
| `-CXXConstructorDecl 0xd73410 <col:8> col:8 implicit A 'void (struct A &&)'
inline noexcept-unevaluated 0xd73410
| `-ParmVarDecl 0xd734d0 <col:8> col:8 'struct A &&'
`-CXXConstructorDecl 0xd73510 parent 0xd2e360 prev 0xd2e4f0 <line:9:1, col:9>
col:4 A 'void (void)'
|-CXXCtorInitializer Field 0xd72f40 'm2' 'B<int>':'struct A::B<int>'
| |-CXXConstructExpr 0xd735b8 <col:4> 'B<int>':'struct A::B<int>' 'void
(void)'
`-CompoundStmt 0xd73608 <col:8, col:9></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>