Skip to content

Conversation

@chqrlie
Copy link
Contributor

@chqrlie chqrlie commented Aug 26, 2025

  • output values of non-literal assert expression comparison operands
  • output values of non-literal static_assert operands

@chqrlie chqrlie force-pushed the static-assert branch 4 times, most recently from 4c54444 to dcdb2f6 Compare August 30, 2025 18:37
@bvdberg
Copy link
Member

bvdberg commented Aug 31, 2025

old:
static_assert(3, 4); // @error{static_assert failed, expected 3, got 4}
new:
static_assert(3, 4); // @error{static_assert failed: 3 == 4}

I think the old message is clearer right? with 3==4 you dont know which was correct?

This patch also grows the c2c binary by 12 KB...

@chqrlie
Copy link
Contributor Author

chqrlie commented Aug 31, 2025

old: static_assert(3, 4); // @error{static_assert failed, expected 3, got 4}

new: static_assert(3, 4); // @error{static_assert failed: 3 == 4}

I think the old message is clearer right? with 3==4 you dont know which was correct?

I made the error message consistent with assert(3 == 4). If both arguments are literals, there is no correct argument value, and the assertion that failed is effectively 3 == 4. If you write static_assert(sizeof(S), 4), then the message is static_assert failed: sizeof(S) == 4, got 3, maybe it should be static_assert failed: sizeof(S) == 4, sizeof(S): 3.

With this PR, assert(sizeof(S) == 4); produces a runtime error Assertion failed: sizeof(S) == 4, sizeof(S): 3`

My goal is to make static_assert more consistent with the C and C++ equivalent where the assertion is an expression, not 2 separate arguments and consistent with the assert statement, producing more explicit error messages.

This patch also grows the c2c binary by 12 KB...

The code generated for the 345 assert statements is slightly larger with the explicit sub-expression strings and computed values. I can try and reduce the number of strings generated.

@chqrlie chqrlie force-pushed the static-assert branch 4 times, most recently from ce5ef56 to 2ddb617 Compare September 3, 2025 09:00
@chqrlie chqrlie force-pushed the static-assert branch 3 times, most recently from c4e5329 to dab58eb Compare September 14, 2025 20:47
@chqrlie chqrlie force-pushed the static-assert branch 2 times, most recently from 8576aad to bad0a66 Compare September 28, 2025 14:49
@chqrlie chqrlie force-pushed the static-assert branch 6 times, most recently from 56facbc to 9f791cc Compare October 8, 2025 09:40
@chqrlie chqrlie force-pushed the static-assert branch 4 times, most recently from 0687b94 to f871efd Compare October 18, 2025 20:12
@chqrlie chqrlie force-pushed the static-assert branch 3 times, most recently from 0612703 to 41b777a Compare October 20, 2025 20:58
@chqrlie chqrlie force-pushed the static-assert branch 2 times, most recently from 2260d9d to ccedfdd Compare November 2, 2025 14:53
@chqrlie chqrlie force-pushed the static-assert branch 7 times, most recently from 0da3aa6 to 26dd896 Compare November 10, 2025 11:09
@chqrlie chqrlie force-pushed the static-assert branch 7 times, most recently from 9951657 to ad3d5f4 Compare November 23, 2025 21:52
* output values of non-literal assert expression comparison operands
* output values of non-literal static_assert operands
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.

2 participants