r181971 - Check a pointer is not null before attempting to use it. This prevents a
Richard Trieu
rtrieu at google.com
Wed May 15 19:14:08 PDT 2013
Author: rtrieu
Date: Wed May 15 21:14:08 2013
New Revision: 181971
URL: http://llvm.org/viewvc/llvm-project?rev=181971&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaTemplate/function-template-specialization.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=181971&r1=181970&r2=181971&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 15 21:14:08 2013
@@ -6405,8 +6405,10 @@ Sema::ActOnFunctionDeclarator(Scope *S,
// 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
Modified: cfe/trunk/test/SemaTemplate/function-template-specialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/function-template-specialization.cpp?rev=181971&r1=181970&r2=181971&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/function-template-specialization.cpp (original)
+++ cfe/trunk/test/SemaTemplate/function-template-specialization.cpp Wed May 15 21:14:08 2013
@@ -46,3 +46,12 @@ namespace PR8295 {
template <typename T> void f(T t) {}
template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}}
}
+
+class Foo {
+ template<class T>
+ 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}}
+};
More information about the cfe-commits
mailing list