On 2022-07-12 06:56:34 +0800, Ziyao wrote:
> > while with tcc:
> > 
> > zira:~> tcc -E err.c
> > # 1 "err.c"
> > # 1 "<command line>" 1
> > # 2 "err.c" 2
> > 
> > 
> > "
> > FOO
> > "
> > "FOO"
> > 
> > which makes more sense as an extension, IMHO. But tcc doesn't give
> > any diagnostic there, and I think that this is incorrect.
> 
> It seems that TinyCC parses the first three lines as a string
> literature,does't it?

Yes, tcc ends the string literal only at a terminating " character
and seems to accept anything before it. This can be seen on

#define FOO bar
"
FOO

which gives an error

  err.c:4: error: missing terminating " character

at line 4.

> But according to C99 standard,
> 
> string-literal:
>       " s-char-sequenceopt "
>       L" s-char-sequenceopt "
> s-char-sequence:
>       s-char
>       s-char-sequence s-char
> s-char:
>       any member of the source character set except the double-quote ",
>       backslash \, or new-line character
>       escape-sequence
> 
> New-line character cannot be included in a string literature.

For this reason, this violates a syntax rule, and the C standard
says "A conforming implementation shall produce at least one
diagnostic message [...] if a preprocessing translation unit
or translation unit contains a violation of any syntax rule
or constraint [...]". That's why I said that there should be
a diagnostic. So the missing diagnostic with tcc is a bug.

If the program is not rejected, the behavior is undefined.

-- 
Vincent Lefèvre <vinc...@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to