Issue 178721
Summary [clang-tidy] New check: modernize-use-static-assert-of-non-value-dependent
Labels clang-tidy
Assignees
Reporter denzor200
    Starting from C++23, `static_assert(false)` can be used directly in template definitions without causing immediate compilation errors, making various workarounds obsolete. I propose adding a new clang-tidy check that modernizes code by replacing deprecated patterns with the new C++23-compliant `static_assert(false)`.

EXAMPLE:
```
template<typename>
struct AlwaysFalse : std::false_type {};

template<typename T>
void foo() {
- static_assert(AlwaysFalse<T>::value, "Error message");
+ static_assert(false, "Error message");
}

template<typename T>
void bar() {
-    static_assert(false && sizeof(T), "Unsupported type");
+ static_assert(false, "Unsupported type");
}
```

This transformation is safe when:
1. The `static_assert` is inside a template
2. The _expression_ is immediately false (not conditionally false based on template arguments)
3. The _expression_ depends on one or more template parameters

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to