[PATCH] D69518: [Diagnostics] Warn for std::is_constant_evaluated in constexpr mode

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 15:02:12 PDT 2019


rsmith added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8410
+  "'std::is_constant_evaluated' will always evaluate to "
+  "'true' in constexpr mode">, InGroup<TautologicalCompare>;
 def warn_comparison_bitwise_always : Warning<
----------------
"constexpr mode" isn't a thing. Maybe just "in this context"?

I think this should have its own warning group, not be grouped under `-Wtautological-compare`.


================
Comment at: clang/lib/Sema/SemaExprCXX.cpp:3694
   // FIXME: Return this value to the caller so they don't need to recompute it.
+  checkStdIsConstantEvaluated(*this, CondExpr, IsConstexpr);
   llvm::APSInt Value(/*BitWidth*/1);
----------------
As noted in PR42977, we should warn whenever we find a call to `is_constant_evaluated` in a manifestly constant evaluated expression, not only in the condition of a constexpr `if`.

This can be checked in ExprConstant.cpp when we evaluate a call to `__builtin_is_constant_evaluated`: if we're about to return `true` from `__builtin_is_constant_evaluated`, and there's either no calls on the call stack or exactly one call which is to `std::is_constant_evaluated`, then warn.


================
Comment at: clang/test/SemaCXX/warn-std-is-constant-evaluated-constexpr.cpp:2
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify -Wtautological-compare %s
+
----------------
This second `RUN` line doesn't add any value; remove it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69518





More information about the cfe-commits mailing list