Non-constant expressions do not fail a static_assert (#2215)

This commit is contained in:
Rangi authored and GitHub committed 2026-10-14 19:24:47 -04:00
1 parent ddd4ba9952
commit 586bd2eec8
8 files changed
+11 -20

No files matched your search

+3 -2
View File
@@ -132,8 +132,9 @@ void act_Assert(AssertionType type, Expression const &expr, std::string const &m
}
}
void act_StaticAssert(AssertionType type, int32_t condition, std::string const &message) {
if (!condition) {
void act_StaticAssert(AssertionType type, Expression const &expr, std::string const &message) {
// If `expr` is not a known constant, `expr.getConstVal()` will print its own error.
if (int32_t condition = expr.getConstVal(); expr.isKnown() && !condition) {
failAssert(type, message);
}
}
+2 -2
View File
@@ -761,10 +761,10 @@ assert:
| POP_ASSERT assert_type relocexpr COMMA string {
act_Assert($2, $3, $5);
}
| POP_STATIC_ASSERT assert_type iconst {
| POP_STATIC_ASSERT assert_type relocexpr {
act_StaticAssert($2, $3, "");
}
| POP_STATIC_ASSERT assert_type iconst COMMA string {
| POP_STATIC_ASSERT assert_type relocexpr COMMA string {
act_StaticAssert($2, $3, $5);
}
;