Detect attempts to provide a specialization of a function within a

dependent scope and produce an error (rather than crashing). Fixes PR8979.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127749 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2011-03-16 19:27:09 +00:00
Родитель 3cd0128ce4
Коммит eef7ac5837
3 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -1733,6 +1733,8 @@ def err_template_spec_default_arg : Error<
def err_not_class_template_specialization : Error<
"cannot specialize a %select{dependent template|template template "
"parameter}0">;
def err_function_specialization_in_class : Error<
"cannot specialize a function %0 within class scope">;
// C++ class template specializations and out-of-line definitions
def err_template_spec_needs_header : Error<

Просмотреть файл

@ -4102,9 +4102,15 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Previous))
NewFD->setInvalidDecl();
} else if (isFunctionTemplateSpecialization) {
if (CheckFunctionTemplateSpecialization(NewFD,
(HasExplicitTemplateArgs ? &TemplateArgs : 0),
Previous))
if (CurContext->isDependentContext() && CurContext->isRecord()
&& !isFriend) {
Diag(NewFD->getLocation(), diag::err_function_specialization_in_class)
<< NewFD->getDeclName();
NewFD->setInvalidDecl();
return 0;
} else if (CheckFunctionTemplateSpecialization(NewFD,
(HasExplicitTemplateArgs ? &TemplateArgs : 0),
Previous))
NewFD->setInvalidDecl();
} else if (isExplicitSpecialization && isa<CXXMethodDecl>(NewFD)) {
if (CheckMemberSpecialization(NewFD, Previous))

Просмотреть файл

@ -237,3 +237,15 @@ void test_func_template(N0::X0<void *> xvp, void *vp, const void *cvp,
xvp.ft1(vp, i);
xvp.ft1(vp, u);
}
namespace PR8979 {
template<typename Z>
struct X0 {
template <class T, class U> class Inner;
struct OtherInner;
template<typename T, typename U> void f(Inner<T, U>&);
typedef Inner<OtherInner, OtherInner> MyInner;
template<> void f(MyInner&); // expected-error{{cannot specialize a function 'f' within class scope}}
};
}