From bd1de1e7dc66a20237a24fdda6e9cd565beb8e12 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 21 May 2025 23:36:33 +0200 Subject: [PATCH] `&&&` was accidentally available as a valid prefix operator. --- releasenotes.md | 1 + src/compiler/parse_expr.c | 6 ++++++ test/test_suite/expressions/addr_fail_2.c3 | 10 ++++++++++ 3 files changed, 17 insertions(+) create mode 100644 test/test_suite/expressions/addr_fail_2.c3 diff --git a/releasenotes.md b/releasenotes.md index 77b5ac30c..c727a6779 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -35,6 +35,7 @@ - Error when using named argument on trailing macro body expansion #2139. - Designated const initializers with `{}` would overwrite the parent field. - Empty default case in @jump switch does not fallthrough #2147. +- `&&&` was accidentally available as a valid prefix operator. ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index c19f004d4..651d816e0 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -703,7 +703,13 @@ static Expr *parse_unary_expr(ParseContext *c, Expr *left) bool is_bangbang = tok_is(c, TOKEN_BANGBANG); Expr *unary = EXPR_NEW_TOKEN(EXPR_UNARY); + if (c->tok == TOKEN_CT_AND) + { + PRINT_ERROR_HERE("'&&&' is the compile time '&&' operator. If you want to take a temp address of an address, use () or space to clarify the intent, e.g. '&&(&a)'."); + return poisoned_expr; + } unary->unary_expr.operator = unaryop_from_token(c->tok); + ASSERT(unary->unary_expr.operator != UNARYOP_ERROR); advance(c); Expr *right_side = parse_precedence(c, PREC_UNARY); diff --git a/test/test_suite/expressions/addr_fail_2.c3 b/test/test_suite/expressions/addr_fail_2.c3 new file mode 100644 index 000000000..841d8335c --- /dev/null +++ b/test/test_suite/expressions/addr_fail_2.c3 @@ -0,0 +1,10 @@ +import std; + +fn int main() +{ + // This works + int** my_super_cool_pointer = &&(&&1); + // This doesn't + int** my_super_cool_pointer2 = &&&&1; // #error: '&&&' is the compile time '&&' operator + return 0; +}