forked from OSchip/llvm-project
When declaring a friend class template, we may end up finding an
injected-class-name (e.g., when we're referring to other specializations of the current class template). Make sure that we see the template rather than the injected-class-name. Fixes PR4768. llvm-svn: 83672
This commit is contained in:
parent
e19c1810d7
commit
7f34baeb4b
|
@ -616,6 +616,22 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK,
|
|||
// whether this is a valid redeclaration.
|
||||
ClassTemplateDecl *PrevClassTemplate
|
||||
= dyn_cast_or_null<ClassTemplateDecl>(PrevDecl);
|
||||
|
||||
// We may have found the injected-class-name of a class template,
|
||||
// class template partial specialization, or class template specialization.
|
||||
// In these cases, grab the template that is being defined or specialized.
|
||||
if (!PrevClassTemplate && PrevDecl && isa<CXXRecordDecl>(PrevDecl) &&
|
||||
cast<CXXRecordDecl>(PrevDecl)->isInjectedClassName()) {
|
||||
PrevDecl = cast<CXXRecordDecl>(PrevDecl->getDeclContext());
|
||||
PrevClassTemplate
|
||||
= cast<CXXRecordDecl>(PrevDecl)->getDescribedClassTemplate();
|
||||
if (!PrevClassTemplate && isa<ClassTemplateSpecializationDecl>(PrevDecl)) {
|
||||
PrevClassTemplate
|
||||
= cast<ClassTemplateSpecializationDecl>(PrevDecl)
|
||||
->getSpecializedTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
if (PrevClassTemplate) {
|
||||
// Ensure that the template parameter lists are compatible.
|
||||
if (!TemplateParameterListsAreEqual(TemplateParams,
|
||||
|
|
|
@ -28,3 +28,19 @@ namespace N {
|
|||
template<typename T> void f0(T) { }
|
||||
template<typename T> void f1(T) { } // expected-error{{redefinition}}
|
||||
}
|
||||
|
||||
// PR4768
|
||||
template<typename T>
|
||||
struct X0 {
|
||||
template<typename U> friend struct X0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct X0<T*> {
|
||||
template<typename U> friend struct X0;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct X0<int> {
|
||||
template<typename U> friend struct X0;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue