[clang-tools-extra] [clang-tidy] Add `modernize-use-if-consteval` check (PR #189743)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 1 00:24:58 PDT 2026


https://github.com/zeyi2 commented:

I also found an invalid fixit:

Repro:
```cpp
namespace std {
constexpr bool is_constant_evaluated() noexcept {
  return __builtin_is_constant_evaluated();
}
}

bool runtime_predicate();

int outer_else_if() {
  if (std::is_constant_evaluated())
    return 1;
  else if (runtime_predicate())
    return 2;
  return 0;
}
```

The check would modify it to:

```cpp
int outer_else_if() {
  if consteval {
    return 1;
  } else if (runtime_predicate())
    return 2;
  return 0;
}
```

and `clang++ -std=c++23 -fsyntax-only` gives an compile error.

https://github.com/llvm/llvm-project/pull/189743


More information about the cfe-commits mailing list