From f87ccb46d7c3ef0017ad5b40f3de96b717dce6b3 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Fri, 25 Jan 2019 17:01:42 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352219 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ lib/Sema/SemaDecl.cpp | 6 +++++- test/SemaCXX/warn-static-outside-class-definition.cpp | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/SemaCXX/warn-static-outside-class-definition.cpp diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1a8f5c1307..b1cd8f7046 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1585,6 +1585,9 @@ def err_explicit_non_ctor_or_conv_function : Error< 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; 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">; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 9f00a5ee2a..4894b9ee30 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8625,8 +8625,12 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, // 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()); } diff --git a/test/SemaCXX/warn-static-outside-class-definition.cpp b/test/SemaCXX/warn-static-outside-class-definition.cpp new file mode 100644 index 0000000000..5235d35cb1 --- /dev/null +++ b/test/SemaCXX/warn-static-outside-class-definition.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s + +struct C { + template static int foo(T); +}; + +template static int C::foo(T) { + //expected-warning@-1 {{'static' can only be specified inside the class definition}} + return 0; +} + -- 2.50.1