Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -8632,9 +8632,10 @@ // 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 or class member template declaration, warn about this. Diag(D.getDeclSpec().getStorageClassSpecLoc(), - NewFD->getDescribedFunctionTemplate() && getLangOpts().MSVCCompat + (cast(DC)->getDescribedClassTemplate() || + NewFD->getDescribedFunctionTemplate()) && getLangOpts().MSVCCompat ? diag::ext_static_out_of_line : diag::err_static_out_of_line) << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc()); } Index: test/SemaCXX/warn-static-outside-class-definition.cpp =================================================================== --- test/SemaCXX/warn-static-outside-class-definition.cpp +++ test/SemaCXX/warn-static-outside-class-definition.cpp @@ -9,3 +9,7 @@ return 0; } +template struct S { void f(); }; + +template static void S::f() {} + //expected-warning@-1 {{'static' can only be specified inside the class definition}}