]> granicus.if.org Git - clang/commitdiff
Check a pointer is not null before attempting to use it. This prevents a
authorRichard Trieu <rtrieu@google.com>
Thu, 16 May 2013 02:14:08 +0000 (02:14 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 16 May 2013 02:14:08 +0000 (02:14 +0000)
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

lib/Sema/SemaDecl.cpp
test/SemaTemplate/function-template-specialization.cpp

index 49be515f0b4e0088f9ebb4508689ca200e413820..885e8759422c1ff1faf565c7f99d5c55f6c3cfc5 100644 (file)
@@ -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
index a0d41b2053443faa113254acee32387d1f232821..2338b6701c44065ecc273f1bb40710c4c1cd9c0b 100644 (file)
@@ -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}}
+};