[llvm-bugs] [Bug 25266] New: Clang fails to compile (possibly) legal code

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 20 12:18:33 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=25266

            Bug ID: 25266
           Summary: Clang fails to compile (possibly) legal code
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hyrosen at mail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

Here's a bit of code which clang 3.7 doesn't compile:


template <class T> struct R { static T& r(); };
struct M {
    static char m(M&);
    template <class T>
    static int m(const T&);
};
template <class T> struct A;
template <class T>
struct B {
    struct U { };
    struct V { M& operator, (U) const; };
    enum { v = sizeof(M::m((R<V>::r(), R<A<T>*>::r()))) };
};
template <class T> struct A { B<T> y; };
int main()
{
//  A<int>();  // Works if uncommented.
    B<int>();
}


Clang reports
h.cpp:14:36: error: field has incomplete type 'B<int>'
template <class T> struct A { B<T> y; };
                                   ^
h.cpp:12:38: note: in instantiation of template class 'A<int>' requested here
    enum { v = sizeof(M::m((R<V>::r(), R<A<T>*>::r()))) };
                                     ^
h.cpp:18:5: note: in instantiation of template class 'B<int>' requested here
    B<int>();
    ^
h.cpp:9:8: note: definition of 'B<int>' is not complete until the closing '}'
struct B {
       ^
1 error generated.

If I uncomment the marked line, clang compiles the code.  I don't know why the
compiler wants A<T> to be complete when it's just dealing with A<T>*, or why
uncommenting the marked line helps.

-- 
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/20151020/0b000bc6/attachment.html>


More information about the llvm-bugs mailing list