jhjourdan / C11parser

A correct C89/C90/C99/C11/C18 parser written using Menhir and OCaml
Other
190 stars 16 forks source link

Questions about test aligned_struct_c18.c #25

Closed zmajeed closed 3 months ago

zmajeed commented 3 months ago

This is tests/aligned_struct_c18.c

struct {
  _Alignas(int) char x;
};

And how it's listed in tests/tests.t

SHOULD FAIL (does not because we do not have a semantic analysis):
  $ $PARSECMD < $TESTDIR/aligned_struct_c18.c

There are some issues with this test

  1. The file fails to parse with GCC-14 with an error that has nothing to do with _Alignas
    
    gcc -std=c18 -fsyntax-only -Wpedantic -pedantic-errors tests/aligned_struct_c18.c

tests/aligned_struct_c18.c:3:1: error: unnamed struct/union that defines no instances 3 | }; | ^


2. Indeed gcc successfully parses the following modified test
```c
struct {
  _Alignas(int) char x;
} a;
  1. So I don't get the purpose of this test - was it motivated by a limitation in C11 that was corrected with DR 444 - https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_444.htm?

    there is no way in the syntax to apply such an alignment to a member

If that's the case then why would semantic analysis be needed for _Alignas to not be recognized inside a struct since the limitation was purely syntactical.

jhjourdan commented 3 months ago

The comment "SHOULD FAIL" in tests.t only apply for the test bitfield_declaration_ambiguity.fail.c, but not for the test aligned_strut_c18.c. This test does not fail, as dictated by the standard.

But you are right that the file is rejected by GCC. I consider this as a "semantic" error, and not as a syntax error, because the input file is correct with respect to the grammar of the standard (even if it is not when considering other rules in the standard). Anyway, I fixed the issue in c42449d5a.

zmajeed commented 3 months ago

Thanks for the quick turnaround - and for clarifying the SHOULD_FAIL label in `tests.t