From: Richard Trieu Date: Thu, 16 May 2013 02:14:08 +0000 (+0000) Subject: Check a pointer is not null before attempting to use it. This prevents a X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62ab010d5acb3752475bf0caf918406c470f7063;p=clang Check a pointer is not null before attempting to use it. This prevents a crash on an explicit specialization of a member function in a class scope. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181971 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 49be515f0b..885e875942 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6405,8 +6405,10 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // C++ [dcl.stc]p1: // A storage-class-specifier shall not be specified in an explicit // specialization (14.7.3) - if (SC != SC_None) { - if (SC != NewFD->getTemplateSpecializationInfo()->getTemplate()->getTemplatedDecl()->getStorageClass()) + FunctionTemplateSpecializationInfo *Info = + NewFD->getTemplateSpecializationInfo(); + if (Info && SC != SC_None) { + if (SC != Info->getTemplate()->getTemplatedDecl()->getStorageClass()) Diag(NewFD->getLocation(), diag::err_explicit_specialization_inconsistent_storage_class) << SC diff --git a/test/SemaTemplate/function-template-specialization.cpp b/test/SemaTemplate/function-template-specialization.cpp index a0d41b2053..2338b6701c 100644 --- a/test/SemaTemplate/function-template-specialization.cpp +++ b/test/SemaTemplate/function-template-specialization.cpp @@ -46,3 +46,12 @@ namespace PR8295 { template void f(T t) {} template void f(T* t) {} // expected-error{{function template partial specialization is not allowed}} } + +class Foo { + template + static void Bar(const T& input); + + // Don't crash here. + template<> + static void Bar(const long& input) {} // expected-error{{explicit specialization of 'Bar' in class scope}} +};