Skip to content

Conversation

@dalg24
Copy link
Member

@dalg24 dalg24 commented Jul 2, 2025

This is indended as support for filing a LWG issue. The implementation was suggested by Nikolas in https://github.com/llvm/llvm-project/pull/122603/files#r2035285951

This is indended as support for filing a LWG issue.
The implementation was suggested by Nikolas in https://github.com/llvm/llvm-project/pull/122603/files#r2035285951
@EricWF
Copy link
Member

EricWF commented Jul 2, 2025

FYI, I'm not sure this approach is actually conforming. I was looking into this and came up with this test case:

extern int z;
alignas(8) int z;

bool test() {
    const bool is_aligned = is_sufficiently_aligned<8>(&z);
    assert(is_sufficiently_aligned<8>(&z) == is_aligned); // fails
}

https://godbolt.org/z/jerx3KjW4

@efriedma-quic
Copy link
Collaborator

We have __builtin_is_aligned, which I think is what you want?

@dalg24
Copy link
Member Author

dalg24 commented Jul 3, 2025

We have __builtin_is_aligned, which I think is what you want?

Thanks for pointing that one out. That looks that the way to go for Clang but it is not provided by GCC.

# else
if constexpr (is_constant_evaluated())
if consteval {
return __builtin_constant_p(__builtin_assume_aligned(__ptr, _Alignment) != nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer simply not supporting constexpr with GCC here.
It seems better to fail loudly than to give the wrong result.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal was to determine whether or not it is implementable, and potentially opening a LWG issue before C++26 is shipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants