[PATCH] D55500: [Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 9 17:49:48 PST 2018


EricWF created this revision.
EricWF added reviewers: rsmith, MaskRay, bruno, void.
Herald added a subscriber: kristina.

This patch implements `__builtin_is_constant_evaluated` as specifier by P0595R2 <https://wg21.link/p0595r2>. It is built on the back of Bill Wendling's work for `__builtin_constant_p()`.

More tests to come, but early feedback is appreciated.

I plan to implement warnings for common mis-usages like those belowe in a following patch:

  void foo(int x) {
    if constexpr (std::is_constant_evaluated())) { // condition is always `true`. Should use plain `if` instead.
     foo_constexpr(x);
    } else {
      foo_runtime(x);
    }
  }




Repository:
  rC Clang

https://reviews.llvm.org/D55500

Files:
  include/clang/Basic/Builtins.def
  lib/AST/ExprConstant.cpp
  lib/Basic/Builtins.cpp
  test/CodeGenCXX/builtin-is-constant-evaluated.cpp
  test/Sema/builtins.c
  test/SemaCXX/builtin-is-constant-evaluated.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55500.177450.patch
Type: text/x-patch
Size: 9637 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181210/fb8d5f2c/attachment.bin>


More information about the cfe-commits mailing list