]> granicus.if.org Git - clang/commit
[Builtins] Implement __builtin_is_constant_evaluated for use in C++2a
authorEric Fiselier <eric@efcs.ca>
Wed, 24 Apr 2019 02:23:30 +0000 (02:23 +0000)
committerEric Fiselier <eric@efcs.ca>
Wed, 24 Apr 2019 02:23:30 +0000 (02:23 +0000)
commit418eae9689448e9a0cf7abcda8cca56f420b752f
treea874f64f457a1cbd08a06276c0b5b2f7efe60b58
parentaf8f9ae48b8935e46f8031dd2c2e8ab285867b07
[Builtins] Implement __builtin_is_constant_evaluated for use in C++2a

Summary:
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);
  }
}
```

Reviewers: rsmith, MaskRay, bruno, void

Reviewed By: rsmith

Subscribers: dexonsmith, zoecarver, fdeazeve, kristina, cfe-commits

Differential Revision: https://reviews.llvm.org/D55500

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359067 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/Builtins.def
lib/AST/ExprConstant.cpp
lib/Basic/Builtins.cpp
lib/CodeGen/CGDecl.cpp
test/CodeGenCXX/builtin-is-constant-evaluated.cpp [new file with mode: 0644]
test/Sema/builtins.c
test/SemaCXX/builtin-is-constant-evaluated.cpp [new file with mode: 0644]