[Diagnostics] Warn for std::is_constant_evaluated in constexpr mode
authorDávid Bolvanský <david.bolvansky@gmail.com>
Tue, 29 Oct 2019 18:06:48 +0000 (19:06 +0100)
committerDávid Bolvanský <david.bolvansky@gmail.com>
Thu, 31 Oct 2019 09:03:11 +0000 (10:03 +0100)
commitb06305e44949fb843310d27b139e5064b214a838
tree7e0305af30caff001e8e7f34be3b50ec24df45dd
parentc9504954052a7630a6e760006297b5fc73a03e4a
[Diagnostics] Warn for std::is_constant_evaluated in constexpr mode

Summary:
constexpr int fn1() {
  if constexpr (std::is_constant_evaluated()) // condition is always true!
    return 0;
  else
    return 1;
}

constexpr int fn2() {
  if (std::is_constant_evaluated())
    return 0;
  else
    return 1;
}

Solves PR42977

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69518
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
clang/test/SemaCXX/warn-constant-evaluated-constexpr.cpp [new file with mode: 0644]