[cfe-commits] r103952 - in /cfe/trunk: lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.friend/p4.cpp
Douglas Gregor
dgregor at apple.com
Mon May 17 10:57:54 PDT 2010
Author: dgregor
Date: Mon May 17 12:57:54 2010
New Revision: 103952
URL: http://llvm.org/viewvc/llvm-project?rev=103952&view=rev
Log:
Diagnose a redefinition error when there are two instantiations of friend
functions defined inside a class template. Fixes PR6952, the last
Boost.Units failure.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p4.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=103952&r1=103951&r2=103952&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Mon May 17 12:57:54 2010
@@ -2000,7 +2000,8 @@
Diag(Function->getLocation(), diag::err_redefinition)
<< Function->getDeclName();
Diag(Definition->getLocation(), diag::note_previous_definition);
- }
+ Function->setInvalidDecl();
+ }
// We have an explicit instantiation (which already occurred) and an
// implicit instantiation. Return without complaint.
@@ -2027,11 +2028,38 @@
if (PatternDecl)
Diag(PatternDecl->getLocation(),
diag::note_explicit_instantiation_here);
+ Function->setInvalidDecl();
}
return;
}
+ // If this is an instantiation of friend function defined within a class
+ // template or class template specialization or member class thereof,
+ // determine whether there were multiple instantiations of its lexical class.
+ if (PatternDecl->getFriendObjectKind() != Decl::FOK_None) {
+ for (FunctionDecl::redecl_iterator R = Function->redecls_begin(),
+ REnd = Function->redecls_end();
+ R != REnd; ++R) {
+ if (*R != Function &&
+ ((*R)->getFriendObjectKind() != Decl::FOK_None)) {
+ if (const FunctionDecl *RPattern
+ = (*R)->getTemplateInstantiationPattern())
+ if (RPattern->getBody(RPattern)) {
+ InstantiatingTemplate Inst(*this, PointOfInstantiation, Function);
+ if (Inst)
+ return;
+
+ Diag(Function->getLocation(), diag::err_redefinition)
+ << Function->getDeclName();
+ Diag((*R)->getLocation(), diag::note_previous_definition);
+ Function->setInvalidDecl();
+ return;
+ }
+ }
+ }
+ }
+
// C++0x [temp.explicit]p9:
// Except for inline functions, other explicit instantiation declarations
// have the effect of suppressing the implicit instantiation of the entity
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p4.cpp?rev=103952&r1=103951&r2=103952&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p4.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.friend/p4.cpp Mon May 17 12:57:54 2010
@@ -21,20 +21,32 @@
friend void f3(T) { } // expected-error{{redefinition of}}
friend void f4(T) { } // expected-error{{redefinition of}}
friend void f5(T) { } // expected-error{{redefinition of}}
-
- // FIXME: should have a redefinition error for f6(int)
- friend void f6(int) { }
+ friend void f6(int) { } // expected-error{{redefinition of}} \
+ // expected-note{{previous definition}}
};
void f2(int) { } // expected-note{{previous definition}}
void f4(int) { } // expected-note{{previous definition}}
-X1<int> x1a; // expected-note 6{{in instantiation of}}
+X1<int> x1a; // expected-note 7{{in instantiation of}}
void f3(int) { } // expected-note{{previous definition}}
void f5(int) { } // expected-note{{previous definition}}
-X1<float> x1b;
+X1<float> x1b;
X1<double> *X0d() { return 0;}
+
+template<typename T>
+struct X2 {
+ friend void g0(T) { } // expected-error{{redefinition of 'g0'}}
+};
+
+template<typename T>
+struct X3 {
+ friend void g0(T) { } // expected-note{{previous definition is here}}
+};
+
+X2<float> x2; // expected-note{{in instantiation of}}
+X3<float> x3;
More information about the cfe-commits
mailing list