[LLVMbugs] [Bug 21212] New: template instantiation of classes in class contexts fails for fields with in-class initializers

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Oct 8 11:53:53 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21212

            Bug ID: 21212
           Summary: template instantiation of classes in class contexts
                    fails for fields with in-class initializers
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rnk at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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>

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141008/8fc676e7/attachment.html>


More information about the llvm-bugs mailing list