Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -8661,9 +8661,11 @@ // 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 + ((getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2013) && + cast(DC)->getDescribedClassTemplate()) || + (getLangOpts().MSVCCompat && NewFD->getDescribedFunctionTemplate())) ? 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,10 @@ return 0; } +template struct S { + void f(); +}; + +template static void S::f() { + //expected-warning@-1 {{'static' can only be specified inside the class definition}} +}