[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 21 07:14:50 PST 2023


cor3ntin added inline comments.


================
Comment at: clang/docs/ReleaseNotes.rst:62
   directly rather than instantiating the definition from the standard library.
+- Implemented `CWG2518 <https://wg21.link/CWG2518>`_ which allows ``static_assert(false)``
+  not to be ill-formed when its condition is evaluated in a non-instantiated templates.
----------------
shafik wrote:
> I am assuming this will be updated eventually but that version is not the final one and the one that was approved can be found from: https://github.com/cplusplus/papers/issues/1251
> 
> and it here: https://cplusplus.github.io/CWG/issues/2518.html
> 
> I think a better wording would be `would not be ill-formed when evaluated in the context of a template definition`
I'll tweak the comment a bit, thanks.
The link points to the yet-to-be-published core issue list so it will automatically point to the right thing eventually.


================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16824-16841
       if (InnerCond && isa<ConceptSpecializationExpr>(InnerCond)) {
         // Drill down into concept specialization expressions to see why they
         // weren't satisfied.
         Diag(StaticAssertLoc, diag::err_static_assert_failed)
           << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
         ConstraintSatisfaction Satisfaction;
         if (!CheckConstraintSatisfaction(InnerCond, Satisfaction))
----------------
rsmith wrote:
> I wonder if it's worth adding a custom diagnostic (eg, "this template cannot be instantiated: %0") for the case where we're in template instantiation and the expression is the bool literal `false`.
I'm not sure i see the motivation. Why would we want to special case `false`? The expression could also be an always false, never dependent expression


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144285/new/

https://reviews.llvm.org/D144285



More information about the cfe-commits mailing list