[clang-tools-extra] [clang-tidy] add modernize-use-constexpr check (PR #146553)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 2 07:42:39 PDT 2025


5chmidti wrote:

> Another interesting case, it seems somehow multiple constexprs got added, ex:
> 
> ```c++
> template <typename CellType>
> constexpr constexpr constexpr constexpr constexpr constexpr constexpr constexpr int numberOfSidesOfDimension(int dimension);
> ```
> 
> This actually compiles, though with a `-Wduplicate-decl-specifier` warning.

I failed to reproduce this with

```c++
template <typename T>
static T forwardDeclared();

template <typename T>
static T forwardDeclared() { return T{}; }

static void useForwardDeclared() {
    forwardDeclared<int>() + forwardDeclared<double>() + forwardDeclared<char>();
}
```

```diff
 template <typename T>                                                                                                                                        
-static T forwardDeclared();                                
+constexpr static T forwardDeclared();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
 template <typename T>                                                      
-static T forwardDeclared() { return T{}; }
+constexpr static T forwardDeclared() { return T{}; }                                                                                                                                                                                                                                                                       
                                                                  
 static void useForwardDeclared() {                                                                                                                                                                                                                                                                                         
     forwardDeclared<int>() + forwardDeclared<double>() + forwardDeclared<char>();  
```

I had seen this one as well, but it was already fixed in the initial commit, at least I thought.

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


More information about the cfe-commits mailing list