Commit 72c08f7b authored by brianpl's avatar brianpl Committed by Facebook Github Bot

Fix the implementation of max_align_t (#1180)

Summary:
Folly's `folly/lang/Align.h` header defines `folly::max_align_t`, which is usually taken from stdlib. This is to correct an error in legacy implementations of `std::max_align_t`, by logically reconstructing the maximum alignment value in a constexpr context.

`max_align_t` depends on the function `detail::max_align_`, which is supposed to implement a recursive max value function using templates. However, the expression

```
!(a < e) ? a : max_align_(e, es...)
```

does not recursively compute the maximum value over `a`, `e`, `es...`. This expression actually selects the first value that is followed by a lower value.

This error prevents folly from compiling on newer versions of clang, targeting x86, because `folly/CachelinePadded.h` statically checks `max_align_t` in an assertion, and then fails, because it thinks that `AtomicStruct<LifoSemHead, atomic>` is over-aligned.

This corrects the implementation to:

```
!(a < e) ? max_align_(a, es...) : max_align_(e, es...)
```

Pull Request resolved: https://github.com/facebook/folly/pull/1180

Reviewed By: Orvid

Differential Revision: D16079107

Pulled By: yfeldblum

fbshipit-source-id: 13adbd6d1c117b3c547e7116216ee1069129b3c7
parent a8ea86cf
......@@ -31,7 +31,7 @@ constexpr size_t max_align_(std::size_t a) {
}
template <typename... Es>
constexpr std::size_t max_align_(std::size_t a, std::size_t e, Es... es) {
return !(a < e) ? a : max_align_(e, es...);
return !(a < e) ? max_align_(a, es...) : max_align_(e, es...);
}
template <typename... Ts>
struct max_align_t_ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment