c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Enhancement: Disallow concatenating string expressions in initializer/argument list

Open cbuttner opened this issue 6 months ago • 5 comments

const IGNORED_FILES[*] = {
  "test/test_suite/arrays/inferred_array_err.c3",
  "test/test_suite/cast/cast_parse_fails.c3",
  "test/test_suite/cast/cast_parse_fails2.c3",
  "test/test_suite/compile_time/ct_switch_more_checks.c3",
  "test/test_suite/contracts/in_array.c3"
  "test/test_suite/define/common2.c3",
  "test/test_suite/define/define_name_errors.c3",
};

Did you spot the missing comma? I think it's very easy to miss the missing comma and get confused.

I propose string concatenation should be required to be in parenthesis inside an initializer list or part of a function/macro argument list.

cbuttner avatar May 27 '25 11:05 cbuttner

This might be desirable, but it's also surprising and very much special casing things.

lerno avatar May 27 '25 13:05 lerno

I can't see how this could be fixed without special casing in a hard to describe way. Outside of eliminating C style const string concat.

lerno avatar May 28 '25 23:05 lerno

Would emitting a warning also be special casing things?

I imagine a separate linter tool could also warn about this then.

cbuttner avatar May 29 '25 12:05 cbuttner

eliminating C style const string concat.

Personally I would be in favour of that, as it's more explicit to use a multi-line string to signal the programmer's intent if that's desired behavior

joshring avatar May 29 '25 23:05 joshring

@joshring raw strings also completely ignores escapes etc. So they're not the same thing. It's not a replacement. C string concat allows this:

String foo = 
  "okeofkoekfe"
  "foekfeokfok"
  "ofekofkeokf";

Which might be exactly what's desired. So I'm not really interested in killing off that feature, since I use it daily.

lerno avatar Jun 07 '25 00:06 lerno