llvm / llvm/llvm-project

[clang-tidy] Add `modernize-use-if-consteval` check

Open
#189,661 2 comments 0 reactions 0 assignees View on GitHub
c++23 check-request clang-tidy
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

It would be useful to have a clang-tidy check that replaces the canonical C++20 spelling based on `std::is_constant_evaluated()` with `if consteval` in C++23 and later.

Code like this is the only way to check for constant evaluation in C++20:

```cpp
if (std::is_constant_evaluated()) {
return slow_but_constexpr_path();
} else {
return fast_runtime_path();
}
```

but in C++23 the clearer spelling is:

```cpp
if consteval {
return slow_but_constexpr_path();
} else {
return fast_runtime_path();
}
```

This makes the intent more explicit and removes the need to spell a library query for something that is now directly represented in the language.

Contributor guide

Open the contributing guide

Research direction

Start in clang-tidy's existing modernize checks and their tests to understand the check structure and transformation conventions. Use the issue's C++20 and C++23 examples as the initial cases, then add coverage showing the canonical std::is_constant_evaluated() form is recognized and the equivalent if consteval spelling is produced.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.