diff options
| author | gingerBill <bill@gingerbill.org> | 2021-08-23 11:50:02 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-08-23 11:50:02 +0100 |
| commit | cba0bd30f548c6a757a3ed5fb994380a4a10aa2e (patch) | |
| tree | 2a531f0d0d4609e84ab5402f6604a1268fc125cf /src/check_expr.cpp | |
| parent | 276d4b8f0d5c5bcff4b83bab12746dd80e10fc90 (diff) | |
Add suggestions when trying to take the address the a value from a `for`/`switch` statement
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 176685804..329bd0fc9 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1886,7 +1886,17 @@ void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *node) { error(op, "Cannot take the pointer address of '%s' which is a swizzle intermediate array value", str); break; default: - error(op, "Cannot take the pointer address of '%s'", str); + { + begin_error_block(); + defer (end_error_block()); + error(op, "Cannot take the pointer address of '%s'", str); + if (e != nullptr && (e->flags & EntityFlag_ForValue) != 0) { + error_line("\tSuggestion: Did you want to pass the iterable value to the for statement by pointer to get addressable semantics?\n"); + } + if (e != nullptr && (e->flags & EntityFlag_SwitchValue) != 0) { + error_line("\tSuggestion: Did you want to pass the value to the switch statement by pointer to get addressable semantics?\n"); + } + } break; } } |