[all-commits] [llvm/llvm-project] 64216b: [Sema] -Wpointer-bool-conversion: suppress lambda ...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Fri Mar 1 08:58:06 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 64216ba1e427fab1ee38ef9492d3fbca907606b9
https://github.com/llvm/llvm-project/commit/64216ba1e427fab1ee38ef9492d3fbca907606b9
Author: Fangrui Song <i at maskray.me>
Date: 2024-03-01 (Fri, 01 Mar 2024)
Changed paths:
M clang/lib/Sema/SemaChecking.cpp
M clang/test/SemaCXX/warn-bool-conversion.cpp
Log Message:
-----------
[Sema] -Wpointer-bool-conversion: suppress lambda function pointer conversion diagnostic during instantiation (#83497)
I have seen two internal pieces of code that uses a template type
parameter to accept any callable type (function pointer, std::function,
closure type, etc). The diagnostic added in #83152 would require
adaptation to the template, which is difficult and also seems
unnecessary. Example:
```cpp
template <typename... Ts>
static bool IsFalse(const Ts&...) { return false; }
template <typename T, typename... Ts,
typename = typename std::enable_if<std::is_constructible<bool, const T&>::value>::type>
static bool IsFalse(const T& p, const Ts&...) {
return p ? false : true;
}
template <typename... Args>
void Init(Args&&... args) {
if (IsFalse(absl::implicit_cast<const typename std::decay<Args>::type&>(
args)...)) {
// A callable object convertible to false is either a null pointer or a
// null functor (e.g., a default-constructed std::function).
empty_ = true;
} else {
empty_ = false;
new (&factory_) Factory(std::forward<Args>(args)...);
}
}
```
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list