aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2026-01-14 09:45:03 +0000
committerGitHub <noreply@github.com>2026-01-14 09:45:03 +0000
commitbbcbf243a1069eef67426a6b5ba3871e535fad2b (patch)
treea78b7889e980cac8f70d92270c2ec5d8af3059dd
parent9d72025a0b6f7b94682662316b892ece865ad8aa (diff)
parentac35e0336b9c246673f1482ad907c013bfff7938 (diff)
Merge pull request #6131 from FrancisTheCat/master
Add warning for `size_of(&x)` expressions
-rw-r--r--src/check_builtin.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 1b3e6912c..929891826 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -2695,6 +2695,16 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
case BuiltinProc_size_of: {
// size_of :: proc(Type or expr) -> untyped int
+ if (ce->args[0]->kind == Ast_UnaryExpr) {
+ ast_node(arg, UnaryExpr, ce->args[0]);
+ if (arg->op.kind == Token_And) {
+ ERROR_BLOCK();
+
+ warning(ce->args[0], "'size_of(&x)' returns the size of a pointer, not the size of x");
+ error_line("\tSuggestion: Use 'size_of(rawptr)' if you want the size of the pointer");
+ }
+ }
+
Operand o = {};
check_expr_or_type(c, &o, ce->args[0]);
if (o.mode == Addressing_Invalid) {