jhjourdan / C11parser

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

Lexer recognizes "alignof" #5

Closed pmetzger closed 5 years ago

pmetzger commented 5 years ago

The lexer recognizes "alignof", see:

      ("_Alignof", ALIGNOF);
 ...
      ("alignof", ALIGNOF);

I believe alignof is a macro defined in <stdalign.h> and is not a language reserved word. It should probably not be recognized by the lexer as an alias for _Alignof.

pmetzger commented 5 years ago

Patch available in pull request #7

jhjourdan commented 5 years ago

Actually, ISO C11 does require alignof to be a keyword, while _Alignof seems to be merely a GNU artifact.

The issue is that if I don't also declare _Alignof as a keyword, then files preprocessed by gcc willhave alignof replaced with _Alignof because of the macro, and I will fail to parse them...

pmetzger commented 5 years ago

Actually, ISO C11 does require alignof to be a keyword, while _Alignof seems to be merely a GNU artifact.

Not according to C11 draft N1570. See Section A.1.2 on page 459, among a number of places in the document. Also, the definition of stdalign.h in section 7.15, page 268. I'm pretty sure _Alignof is the real one; the policy has been never to introduce a new keyword without a leading _ in order to avoid breaking old code that might use a particular name as an identifier.

See: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

jhjourdan commented 5 years ago

Ah, right. I was looking at n1548, which is different to that respect. Then, I'll merge your pull request.

pmetzger commented 5 years ago

I didn't realize that had been changed so late in the standards process. Interesting! I'll have to make sure that none of my own work was based on 1548 given the changes. BTW, drafts of c17/c18 are available, perhaps I should check for grammar changes...