r360250 - Allow 'static' storage specifier on an out-of-line class member template declaration in MSVCCompat mode.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed May 8 06:24:36 PDT 2019


Author: aaronballman
Date: Wed May  8 06:24:36 2019
New Revision: 360250

URL: http://llvm.org/viewvc/llvm-project?rev=360250&view=rev
Log:
Allow 'static' storage specifier on an out-of-line class member template declaration in MSVCCompat mode.

Patch by Soumi Manna.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=360250&r1=360249&r2=360250&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May  8 06:24:36 2019
@@ -8673,9 +8673,12 @@ Sema::ActOnFunctionDeclarator(Scope *S,
       // member function definition.
 
       // MSVC permits the use of a 'static' storage specifier on an out-of-line
-      // member function template declaration, warn about this.
+      // member function template declaration and class member template
+      // declaration (MSVC versions before 2015), warn about this.
       Diag(D.getDeclSpec().getStorageClassSpecLoc(),
-           NewFD->getDescribedFunctionTemplate() && getLangOpts().MSVCCompat
+           ((!getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015) &&
+             cast<CXXRecordDecl>(DC)->getDescribedClassTemplate()) ||
+           (getLangOpts().MSVCCompat && NewFD->getDescribedFunctionTemplate()))
            ? diag::ext_static_out_of_line : diag::err_static_out_of_line)
         << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc());
     }

Modified: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp?rev=360250&r1=360249&r2=360250&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp Wed May  8 06:24:36 2019
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -fms-compatibility-version=12.0 -verify %s
 
 struct C {
   template <typename T> static int foo(T);
@@ -9,3 +10,13 @@ template <typename T> static int C::foo(
   return 0;
 }
 
+template <class T> struct S { 
+  void f();
+};
+
+template <class T> static void S<T>::f() {}
+#if _MSC_VER >= 1900
+  //expected-error at -2 {{'static' can only be specified inside the class definition}}
+#else
+  //expected-warning at -4 {{'static' can only be specified inside the class definition}}
+#endif




More information about the cfe-commits mailing list