Skip to content

Commit b118d66

Browse files
ispetersclaude
andcommitted
Don't assume a curried int leaves tail padding in function
The test that `function`'s padding is at its end checks that a following `char` fits in the tail padding of `function<int(char)>` and `function<int(int)>`. On 32-bit x86, `function<int(int)>` has no tail padding at all: its 8-byte factory storage, 4-byte operation-state factory pointer and 4-byte `int` fill 16 bytes exactly, so the `char` makes the enclosing object 20 bytes and the assertion fails. The property under test still holds; the test assumed there was padding to reuse. This diff uses `function<int(short)>` instead, which has tail padding wherever pointers are wider than two bytes: two bytes of it on 32-bit x86 and six on x86-64. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9be0310 commit b118d66

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎test/exec/test_function.cpp‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,14 +1762,17 @@ namespace
17621762
// Under the Itanium C++ ABI, a following member can reuse the tail padding of
17631763
// a [[no_unique_address]] member whose type isn't POD for the purpose of
17641764
// layout, so a function whose padding is all at its end leaves room for c.
1765+
// The curried arguments are smaller than a pointer, so each function has
1766+
// tail padding on every target; an int would leave none where pointers are
1767+
// four bytes wide.
17651768
TEST_CASE("function's padding is at its end, where an enclosing object can reuse it",
17661769
"[types][function]")
17671770
{
1768-
using takes_char = exec::function<int(char)>;
1769-
using takes_int = exec::function<int(int)>;
1771+
using takes_char = exec::function<int(char)>;
1772+
using takes_short = exec::function<int(short)>;
17701773

17711774
STATIC_REQUIRE(sizeof(function_then_char<takes_char>) == sizeof(takes_char));
1772-
STATIC_REQUIRE(sizeof(function_then_char<takes_int>) == sizeof(takes_int));
1775+
STATIC_REQUIRE(sizeof(function_then_char<takes_short>) == sizeof(takes_short));
17731776
}
17741777
#endif
17751778

0 commit comments

Comments
 (0)