Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1466,6 +1466,10 @@ def warn_cxx14_compat_inline_variable : Warning< "inline variables are incompatible with C++ standards before C++17">, DefaultIgnore, InGroup; +def warn_cxx17_static_inline : Warning< + "variable %0 declared as both inline and with static storage declaration">, + InGroup; + def warn_inline_namespace_reopened_noninline : Warning< "inline namespace reopened as a non-inline namespace">, Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -7124,6 +7124,11 @@ Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_declaration_block_scope) << Name << FixItHint::CreateRemoval(D.getDeclSpec().getInlineSpecLoc()); + } else if (SC == SC_Static && DC->isFileContext() && + getLangOpts().CPlusPlus17) { + // static inline declarations in the global or namespace scope should get + // a warning indicating they are contradictory in nature. + Diag(D.getIdentifierLoc(), diag::warn_cxx17_static_inline) << Name; } else { Diag(D.getDeclSpec().getInlineSpecLoc(), getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_inline_variable Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp +++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp @@ -4,7 +4,7 @@ A() -> A; A(int) -> A; -static constexpr inline const volatile A a = {}; // ok, specifiers are permitted +static constexpr inline const volatile A a = {}; // expected-warning{{variable 'a' declared as both inline and with static storage declaration}} A b; A c [[]] {}; Index: clang/test/Parser/cxx1z-decomposition.cpp =================================================================== --- clang/test/Parser/cxx1z-decomposition.cpp +++ clang/test/Parser/cxx1z-decomposition.cpp @@ -84,7 +84,7 @@ constexpr auto &[i] = n; // expected-error {{cannot be declared 'constexpr'}} } - static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}} + static constexpr inline thread_local auto &[j1] = n; // expected-error {{cannot be declared with 'constexpr inline' specifiers}} expected-warning{{variable 'j1' declared as both inline and with static storage declaration}} static thread_local auto &[j2] = n; // expected-warning {{declared with 'static thread_local' specifiers is a C++20 extension}} inline auto &[k] = n; // expected-error {{cannot be declared 'inline'}} Index: clang/test/Sema/c17-global-static-inline.cpp =================================================================== --- /dev/null +++ clang/test/Sema/c17-global-static-inline.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -std=c++17 %s -verify + +static inline int should_warn; // expected-warning{{variable 'should_warn' declared as both inline and with static storage declaration}} + +namespace TestNamespace { + +static inline int NamespacedShouldWarn; // expected-warning{{variable 'NamespacedShouldWarn' declared as both inline and with static storage declaration}} + +}; + +static constexpr inline const volatile float f = 0.0f; // expected-warning{{variable 'f' declared as both inline and with static storage declaration}} + +static inline int TestFunction(int s, int e, int n) { + int m = (n - s) / (e - s); + return m * m * m * (m * (m * 6 - 15) + 10); +}