Author: erichkeane Date: Fri Jan 25 09:01:42 2019 New Revision: 352219 URL: http://llvm.org/viewvc/llvm-project?rev=352219&view=rev Log: Allow 'static' storage specifier on an out-of-line member function template declaration in MSVCCompat mode
Microsoft compiler permits the use of 'static' storage specifier outside of a class definition if it's on an out-of-line member function template declaration. This patch allows 'static' storage specifier on an out-of-line member function template declaration with a warning in Clang (To be compatible with Microsoft). Intel C/C++ compiler allows the 'static' keyword with a warning in Microsoft mode. GCC allows this with -fpermissive. Patch By: Manna Differential Revision: https://reviews.llvm.org/D56473 Change-Id: I97b2d9e9d57cecbcd545d17e2523142a85ca2702 Added: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp (with props) Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=352219&r1=352218&r2=352219&view=diff ============================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original) +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 25 09:01:42 2019 @@ -1585,6 +1585,9 @@ def err_explicit_non_ctor_or_conv_functi 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 ext_static_out_of_line : ExtWarn< + err_static_out_of_line.Text>, + InGroup<MicrosoftTemplate>; 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">; Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=352219&r1=352218&r2=352219&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 25 09:01:42 2019 @@ -8625,8 +8625,12 @@ Sema::ActOnFunctionDeclarator(Scope *S, // Complain about the 'static' specifier if it's on an out-of-line // member function definition. + + // MSVC permits the use of a 'static' storage specifier on an out-of-line + // member function template declaration, warn about this. Diag(D.getDeclSpec().getStorageClassSpecLoc(), - diag::err_static_out_of_line) + NewFD->getDescribedFunctionTemplate() && getLangOpts().MSVCCompat + ? diag::ext_static_out_of_line : diag::err_static_out_of_line) << FixItHint::CreateRemoval(D.getDeclSpec().getStorageClassSpecLoc()); } Added: 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=352219&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp (added) +++ cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp Fri Jan 25 09:01:42 2019 @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %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; +} + Propchange: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Rev URL" Propchange: cfe/trunk/test/SemaCXX/warn-static-outside-class-definition.cpp ------------------------------------------------------------------------------ svn:mime-type = text/plain _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits