3 ms·
The only sense in which an unterminated string literal can be UB is like this. It's possible that if a string literal is not terminated, the situation will cau
by kazinator 7y ago
The only sense in which an unterminated string literal can be UB is like this.
It's possible that if a string literal is not terminated, the situation will cause a de facto overly long string literal token to exist. For instance:
const char *str = "short str; int x = 42; and now a realy long line follows ...
if the non-termination causes a de facto large literal to exist in the program, and that large literal exceeds a minimum implementation limit, then that is UB. Probably.
Strictly speaking, since the token is not closed, it is not a string literal, and so any limitation on string literals doesn't apply to it. Unless we interpret that limit as pertaining to the implementation's tokenizer, as such, which can plausibly choke on simply the valid prefix of a string literal that is too long.
Anyway, if a newline occurs before the minimum limit on string literal length is reached, and that newline is not escaped with a backslash, then that is a straightforward syntax error.
- eru 7y agoThe standard could have still made that situation a syntax error, or at least implementation defined behaviour.