[clang-tools-extra] [clang-tidy] Fix `modernize-use-constraints` crash on uses of nonstandard `enable_if`s (PR #152938)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 10 14:04:44 PDT 2025
================
@@ -78,6 +79,15 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
if (!TD || TD->getName() != "enable_if")
return std::nullopt;
+ const TemplateParameterList *Params = TD->getTemplateParameters();
+ if (Params->size() != 2)
+ return std::nullopt;
----------------
vbvictor wrote:
Maybe template-specializations are considered zero parameters?
```cpp
template<typename T>
void foo(T value) {}
// here are 0?
template<>
void foo<double>(double value) {}
```
Or like this?
```cpp
template<typename T>
constexpr bool is_pointer_v = false;
// is this considered 0 because we explicitly specialize 'is_pointer_v'?
template<typename T>
constexpr bool is_pointer_v<T*> = true;
```
We can make condition `if Params->size() >= 1` so it's obvious we check it to access the first argument and no more. Let it have 1, 2, 3, 4... parameters if needed.
https://github.com/llvm/llvm-project/pull/152938
More information about the cfe-commits
mailing list