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

           Summary: Injected friend redefinition
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


this is a stripped-down example from
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38392
which fails to compile on clang.


ga...@google8:~/llvm-build$ cat PR.cpp 
#include <cstdio>

void Function();

int main(int argc, char* argv[])
{
    Function();
}

template <typename T>
struct Test
{
    friend void Function() { printf("Function()"); getchar(); }
};

template class Test<int>;


ga...@google8:~/llvm-build$ /home/gabor/llvm-build/Debug+Asserts/bin/clang
PR.cpp
PR.cpp:13:17: error: redefinition of 'Function'
    friend void Function() { printf("Function()"); getchar(); }
                ^
PR.cpp:16:16: note: in instantiation of template class 'Test<int>' requested
here
template class Test<int>;
               ^
PR.cpp:13:17: note: previous definition is here
    friend void Function() { printf("Function()"); getchar(); }
                ^
1 error generated.


The error comes from

1175          // Check for a function body.
1176          const FunctionDecl *Definition = 0;
1177          if (Function->hasBody(Definition) &&
1178              Definition->getTemplateSpecializationKind() ==
TSK_Undeclared) {
1179            SemaRef.Diag(Function->getLocation(), diag::err_redefinition) 
1180              << Function->getDeclName();
1181            SemaRef.Diag(Definition->getLocation(),
diag::note_previous_definition);
1182            Function->setInvalidDecl();        
1183          } 

in clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

(I verified that the bug was present in r112000, before I started with fiddling
in clang.)

Modern gccs do compile this, but fail to link (see URL). gcc v4.6 should work.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to