Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -1590,6 +1590,9 @@ def err_static_not_bitfield : Error<"static member %0 cannot be a bit-field">; def err_static_out_of_line : Error< "'static' can only be specified inside the class definition">; +def warn_static_out_of_line : Warning< + "'static' can only be specified inside the class definition">, + InGroup; def err_storage_class_for_static_member : Error< "static data member definition cannot specify a storage class">; def err_typedef_not_bitfield : Error<"typedef member %0 cannot be a bit-field">; Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -8625,6 +8625,14 @@ // Complain about the 'static' specifier if it's on an out-of-line // member function definition. + + // MSVC permits the use of 'static' storage specifier on an out-of-line + // member function template declaration, warn about this. + if (NewFD->getDescribedFunctionTemplate() && getLangOpts().MSVCCompat) { + Diag(D.getDeclSpec().getStorageClassSpecLoc(), + diag::warn_static_out_of_line) + << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc()); + } else Diag(D.getDeclSpec().getStorageClassSpecLoc(), diag::err_static_out_of_line) << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc()); Index: test/SemaCXX/warn-static-outside-class-definition.cpp =================================================================== --- /dev/null +++ test/SemaCXX/warn-static-outside-class-definition.cpp @@ -0,0 +1,11 @@ +// RUN: %clang -cc1 -fsyntax-only -verify -fms-compatibility -fms-extensions %s + +struct C{ + template< typename T> static int foo(T); +}; + +template< typename T> static int C::foo(T){ +// expected-warning@-1{{'static' can only be specified inside the class definition}} + return 0; +} +