Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -84,6 +84,7 @@ directly rather than instantiating the definition from the standard library. - Implemented `CWG2518 `_ which allows ``static_assert(false)`` to not be ill-formed when its condition is evaluated in the context of a template definition. +- Declaring namespace std to be an inline namespace is now prohibited, `[namespace.std]p7`. C++20 Feature Support ^^^^^^^^^^^^^^^^^^^^^ Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1579,6 +1579,8 @@ InGroup; def err_inline_namespace_mismatch : Error< "non-inline namespace cannot be reopened as inline">; +def err_inline_namespace_std : Error< + "namespace 'std' cannot be declared to be inline">; def err_unexpected_friend : Error< "friends can only be classes or functions">; Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -11361,6 +11361,14 @@ NamespaceDecl *PrevNS = nullptr; if (II) { + // C++ [namespace.std]p7: + // A translation unit shall not declare namespace std to be an inline + // namespace (9.8.2). + // + // This has to be diagnosed before entering DiagnoseNamespaceInlineMismatch. + if (IsInline && II->isStr("std")) + Diag(InlineLoc, diag::err_inline_namespace_std) + << SourceRange(InlineLoc, InlineLoc.getLocWithOffset(6)); // C++ [namespace.def]p2: // The identifier in an original-namespace-definition shall not // have been previously defined in the declarative region in Index: clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp =================================================================== --- clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp +++ clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp @@ -16,3 +16,6 @@ inline namespace {} // expected-note {{previous definition}} namespace {} // expected-warning {{inline namespace reopened as a non-inline namespace}} } + +inline namespace std {} +// expected-error@-1{{namespace 'std' cannot be declared to be inline}}