From b6f480ebcb237b677577eb10bca0abd39ab9d1bb Mon Sep 17 00:00:00 2001 From: Corentin Jabot Date: Fri, 17 Feb 2023 19:45:30 +0100 Subject: [PATCH] [Clang] Implement CWG2518 - static_assert(false) This allows `static_assert(false)` to not be ill-formed in template definitions. This change is applied as a DR in all C++ modes. Of notes, a couple of tests were relying of the eager nature of static_assert * test/SemaTemplate/instantiation-dependence.cpp * test/SemaTemplate/instantiate-var-template.cpp I don't know if the changes to `static_assert` still allow that sort of tests to be expressed. Reviewed By: #clang-language-wg, erichkeane, aaron.ballman Differential Revision: https://reviews.llvm.org/D144285 --- Fixes the build with newer versions of MSVC's STL, reported as https://github.com/root-project/root/issues/15321 --- interpreter/llvm-project/clang/docs/ReleaseNotes.rst | 2 ++ .../llvm-project/clang/lib/Sema/SemaDeclCXX.cpp | 12 ++++++++++-- .../llvm-project/clang/www/cxx_dr_status.html | 2 +- interpreter/llvm-project/llvm-project.tag | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/interpreter/llvm-project/clang/docs/ReleaseNotes.rst b/interpreter/llvm-project/clang/docs/ReleaseNotes.rst index 03ac96e974853..8d2e0c6764d5c 100644 --- a/interpreter/llvm-project/clang/docs/ReleaseNotes.rst +++ b/interpreter/llvm-project/clang/docs/ReleaseNotes.rst @@ -223,6 +223,8 @@ sections with improvements to Clang's support for those languages. C++ Language Changes -------------------- +- Implemented `CWG2518 `_ which allows ``static_assert(false)`` + to not be ill-formed when its condition is evaluated in the context of a template definition. C++20 Feature Support ^^^^^^^^^^^^^^^^^^^^^ diff --git a/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp b/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp index a33ef91fa109f..1838f5a62be70 100644 --- a/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp +++ b/interpreter/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp @@ -16802,7 +16802,14 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, FoldKind).isInvalid()) Failed = true; - if (!Failed && !Cond) { + // CWG2518 + // [dcl.pre]/p10 If [...] the expression is evaluated in the context of a + // template definition, the declaration has no effect. + bool InTemplateDefinition = + getLangOpts().CPlusPlus && CurContext->isDependentContext(); + + if (!Failed && !Cond && !InTemplateDefinition) { + SmallString<256> MsgBuffer; llvm::raw_svector_ostream Msg(MsgBuffer); if (AssertMessage) { @@ -16833,7 +16840,8 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, DiagnoseStaticAssertDetails(InnerCond); } else { Diag(StaticAssertLoc, diag::err_static_assert_failed) - << !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); + << !AssertMessage << Msg.str() << AssertExpr->getSourceRange(); + PrintContextStack(); } Failed = true; } diff --git a/interpreter/llvm-project/clang/www/cxx_dr_status.html b/interpreter/llvm-project/clang/www/cxx_dr_status.html index 0c621a7894340..acd77bd99b5a9 100755 --- a/interpreter/llvm-project/clang/www/cxx_dr_status.html +++ b/interpreter/llvm-project/clang/www/cxx_dr_status.html @@ -14915,7 +14915,7 @@

C++ defect report implementation status

2518 review Conformance requirements and #error/#warning - Not resolved + Clang 17 2519 diff --git a/interpreter/llvm-project/llvm-project.tag b/interpreter/llvm-project/llvm-project.tag index aa4b18c999ba7..acd21506d992c 100644 --- a/interpreter/llvm-project/llvm-project.tag +++ b/interpreter/llvm-project/llvm-project.tag @@ -1 +1 @@ -ROOT-llvm16-20240402-01 +ROOT-llvm16-20240604-01