<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/146296>146296</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] Check request: misc-constexpr-non-static-in-scope
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          denzor200
      </td>
    </tr>
</table>

<pre>
    Many developers mistakenly believe that `constexpr` variables inside functions **automatically have a static lifetime**, like `static` variables. This common misconception leads to dangerous code that:
- Compiles without errors, but causes undefined behavior (UB) at runtime.
- Hard to detect in code reviews and testing.
- Misleading because constexpr is associated with "compile-time safety".

Need a check that will find `constexpr` non-`static` variables inside a function scope. The check will provide fixit hint to add `static` keyword.

BEFORE:
```
void foo() {
   constexpr int x = 42;
   // ...
}
```

AFTER:
```
void foo() {
   static constexpr int x = 42;
   // ...
}
```

The check will not provide warning for variables outside a function scope:
```
namespace ns {
inline constexpr int MAX_SIZE = 1024;  // OK - no need static here
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVNGK6zYQ_RrlZXBQ5NhJHvzg7G5oKdsLt7dQ-lJkaRxPV5ZcSXY2_foiO0337t6HwgWDwR6dc-ac0cgQ6GwRK1YcWfG4kmPsnK802r-dF5yvGqev1bO0V9A4oXED-gA9hShf0JorNGgIJ4TYyQis5MrZEPF18KzkMElPsjEYgGwgjdCOVkVyNgATNRO1HKPrZSQljblCJycECSGmL2CoxUg9LpVMPIChF0wcS8FXBGv40lEA5fre2aRPOatwSFxgUOoA0YGW9ozejalOL5JZXjNeZ_Dg-oGS0AvFzo0R0HvnQ2JtxghKjgEDjFZjSxY1NNjJiZwHJva_Hpk4gIzgR5sEr2fEH6TXMylGVBHILqQeJ8JLAGk1RAyR7Hmpf6aQhJI9Q4MzH9y9BAogQ3CKZEQ9awQmhFpEZ4kUgmwxXpkQCY7x-mdEDRJUh-plSedCxkBLVn_IyTqbfdvXf4OT9-ggKDdg8htv4DPu4N00J0yvFKEjG1PzUuuvA3vB68V5fdN4fDp9-vy0ZMBKfnt4PTnS0DrHxD5Zy3ZHxmuAt4bYCK_A8kfYCpbffjNxYuIE6_UMv3t8h8p4XZ--PH3-_3y3Sfxu2ndeWRfvfl2ktynz1vk3rrsxftP2j9Kt7DEMUiGkSzULJ2vI4jvVz_Vvf_zy4-9Ps_gNF1uWH-_SP_0EGVgHNs3MrekOPX7sZ6WrXB_yg1xhtdkVG7HdFcV-1VU55-3mUGJZHoq9LHjeHvKy2WKeC77lUqyoElwUvMw53-SHzX4tZLnhB7UTRal220KyLcdeklkbM_Vr588rCmHEarMtxaFcGdmgCfOeEkIZac9ZJJ0GPu0tX6VTWTOeA9tyQyGG_3AiRTNvuDfHikd4mBPx-NeIIS2CeW1kd9uydCsWMzKy2ez_avSm6mIcQkpiNu9MsRubtXI9E6dEeXtlg3d_oopMnOY-AhOnWytTJf4JAAD__8DmvLA">