[LLVMbugs] [Bug 11265] New: Weird compiler error triggered by template friend statement

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Oct 29 17:09:21 PDT 2011


             Bug #: 11265
           Summary: Weird compiler error triggered by template friend
           Product: clang
           Version: 2.9
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: max at quendi.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 7547
  --> attachment.cgi?id=7547
Reduced test case

Compiling the attached file results in a compiler error with Apple clang 3.0 on
my Mac OS X 10.6.8 system:

$ clang -Wall -c test3.cc
test3.cc:15:14: error: no matching constructor for initialization of
        A::C<A::b0> bar;
test3.cc:11:35: note: candidate constructor (the implicit copy constructor) not
viable: requires 1 argument, but 0 were provided
        template <A::B> friend struct A::C;
1 error generated.
$ clang -v
Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin10.8.0
Thread model: posix

Removing the "friend" statement in struct D, or moving either B or C out of
namespace A, as well as all sorts of other minimal changes, gets rid of the
error. In particular, replacing the single friend statement by these two works:
    friend struct A::C<A::b0>;
    friend struct A::C<A::b1>;

If this code is in some way wrong, I fail to see it and would greatly
appreciate any pointers as to in which way it is wrong. But then, the mere fact
that clang claims that the "friend" statement constitutes a copy constructor
makes me think something is very fishy here, even if my code turns out to be
somehow flawed.

Note that this is a heavily reduced version of an error that occurred in
production code. The original errors are of the form

error: 'N::M::C<1, true>::foo' is not a member of class 'N::M::C<1, true>'


error: non-const lvalue reference to type 'N::M::C<1, true>' cannot bind to a
value of unrelated type 'N::M::C<1, true>'

where N, M are namespaces and C a class similar to class C in the attached
example. Here, too, I identified a single friend statement as "cause" of the
problem in the sense that removing it cures the error.

Configure bugmail: userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list