-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[llvm] replace static_assert with std::enable_if_t in ilist_node_impl #127722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] replace static_assert with std::enable_if_t in ilist_node_impl #127722
Conversation
+@compnerd, who helped me figure out this solution |
@llvm/pr-subscribers-llvm-adt Author: Andrew Rogers (andrurogerz) ChangesPurposeRemove BackgroundThis fix is necessary to support building LLVM as a Windows DLL, tracked by #109483. The
Conditionally including the function using ValidationVerified I no longer fail compilation due to the Full diff: https://github.com/llvm/llvm-project/pull/127722.diff 1 Files Affected:
diff --git a/llvm/include/llvm/ADT/ilist_node.h b/llvm/include/llvm/ADT/ilist_node.h
index bfd50f8b3fb71..2148d6fde9be0 100644
--- a/llvm/include/llvm/ADT/ilist_node.h
+++ b/llvm/include/llvm/ADT/ilist_node.h
@@ -18,6 +18,8 @@
#include "llvm/ADT/ilist_node_base.h"
#include "llvm/ADT/ilist_node_options.h"
+#include <type_traits>
+
namespace llvm {
namespace ilist_detail {
@@ -147,9 +149,8 @@ class ilist_node_impl
///
/// This requires sentinel tracking to be explicitly enabled. Use the
/// ilist_sentinel_tracking<true> option to get this API.
+ template <typename = std::enable_if_t<OptionsT::is_sentinel_tracking_explicit>>
bool isSentinel() const {
- static_assert(OptionsT::is_sentinel_tracking_explicit,
- "Use ilist_sentinel_tracking<true> to enable isSentinel()");
return node_base_type::isSentinel();
}
};
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't build with clang: https://buildkite.com/llvm-project/github-pull-requests/builds/148282#01951b84-0e6e-4b7d-8670-082d92441cc7
Should we use void_t
instead?
Fixed by using |
@kuhar any further requests/objections on this patch? |
I think we should wait on #127850 (comment) given that the code works fine in all the configurations supported at the moment. |
I'm not sure I see the reason for that. This is correcting a rather subtle design point in the code which has nothing to do other windows support. Can you help me understand why this is something that we should hold up? |
Can we write a test for this that exercises this without adding |
I don't think that really makes sense. This is a bug that the compiler lets you get away with. We generally do not have tests for miscompilation from a host compiler. |
Merging this on behalf of @andrurogerz |
Purpose
Remove
static_assert
inilist_node_impl::isSentinel
and conditionally include the functino usingstd::enable_if_t
instead.Background
This fix is necessary to support building LLVM as a Windows DLL, tracked by #109483.
The
static_assert
inilist_node_impl::isSentinel
fails when compiling LLVM as a Windows DLL with the options-D LLVM_BUILD_LLVM_DYLIB=ON -D LLVM_BUILD_LLVM_DYLIB_VIS=ON -D LLVM_LINK_LLVM_DYLIB=ON
:Conditionally including the function using
std::enable_if_t
has the same effect of preventing the function's use whenis_sentinel_tracking_explicit=false
, but avoids the issue when DLL-exporting downstream classes.Validation
Verified I no longer fail compilation due to the
static_assert
when building LLVM on Windows 11 with the options-D LLVM_BUILD_LLVM_DYLIB=ON -D LLVM_BUILD_LLVM_DYLIB_VIS=ON -D LLVM_LINK_LLVM_DYLIB=ON
.