Skip to content

Language.C.Parser.Lexer: accept C23 bool keyword #104

Merged
Bodigrim merged 2 commits into
visq:masterfrom
sternenseemann:c23-bools
Mar 11, 2026
Merged

Language.C.Parser.Lexer: accept C23 bool keyword #104
Bodigrim merged 2 commits into
visq:masterfrom
sternenseemann:c23-bools

Conversation

@sternenseemann
Copy link
Copy Markdown

@sternenseemann sternenseemann commented Jan 31, 2026

C23 makes bool a proper keyword and C preprocessors will no longer
expand it to _Bool which remains a valid alias. This is relatively
simple to support and unbreaks a lot of packages that use c2hs
with gcc 15 which defaults to -std=c23.

It fixes the build of all Hackage packages that use c2hs and break with GCC 15 (heystone, nfc, regex-rure, hd5-lite) except for avif which requires [[nodiscard]].

- This requires naming the int128 token correctly in tokenlist.txt.
- The #ifdef needs to be restored manually after generation,
  unfortunately.
- CTokFloatN 16 moves around, but stays within the #ifdef
- CTokBFloat16 moves around, but stays outside the #ifdef
C23 makes bool a proper keyword and C preprocessors will no longer
expand it to `_Bool` which remains a valid alias. This is relatively
simple to support and unbreaks a lot of packages that use c2hs
with gcc 15 which defaults to -std=c23.

Fixes build of Hackage packages hd5-lite, heystone, nfc, regex-rure.
@sternenseemann
Copy link
Copy Markdown
Author

enum-mode-2.i from the harness tests fails now. I would vote to change that test case, since the code in question is no longer valid C23, but maybe someone else should comment on this.

typedef enum _eq_bool bool;

@Bodigrim
Copy link
Copy Markdown
Collaborator

Thanks!

@Bodigrim
Copy link
Copy Markdown
Collaborator

I would vote to change that test case

Could you please submit a patch?

@sternenseemann sternenseemann deleted the c23-bools branch March 11, 2026 22:28
sternenseemann added a commit to sternenseemann/language-c that referenced this pull request Mar 11, 2026
The test suite has been failing after visq#104 since language-c would
reject `bool` occurring in places where a keyword may not (as would
a C compiler/preprocessor).

gcc_dg_pre.tar.bz2 contains C preprocessor output generated with
older versions of GCC using older versions of the C standard. In
particular `bool` is used as a variable name and as a (custom)
type name in some of preprocessor outputs.

Since the tarball doesn't contain the original C files the output
was generated from, I resorted to haphazardly editing the outputs.
I made the following modifications:

- pr38948.i: removed `typedef unsigned char bool;`
- pr37684.i: removed `typedef int bool;`
- enum-mode-2.i: renamed `typedef … bool;` to `typedef … my_bool`
- Wcxx-compat-2.i: removed `int bool;` declaration
@sternenseemann
Copy link
Copy Markdown
Author

#105 Looks like CI doesn't run the full test suite?

@Bodigrim
Copy link
Copy Markdown
Collaborator

Looks like CI doesn't run the full test suite?

Yeah, I think it does not. I'd welcome a PR fixing this, perhaps as a separate job.

Bodigrim pushed a commit that referenced this pull request Mar 14, 2026
The test suite has been failing after #104 since language-c would
reject `bool` occurring in places where a keyword may not (as would
a C compiler/preprocessor).

gcc_dg_pre.tar.bz2 contains C preprocessor output generated with
older versions of GCC using older versions of the C standard. In
particular `bool` is used as a variable name and as a (custom)
type name in some of preprocessor outputs.

Since the tarball doesn't contain the original C files the output
was generated from, I resorted to haphazardly editing the outputs.
I made the following modifications:

- pr38948.i: removed `typedef unsigned char bool;`
- pr37684.i: removed `typedef int bool;`
- enum-mode-2.i: renamed `typedef … bool;` to `typedef … my_bool`
- Wcxx-compat-2.i: removed `int bool;` declaration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants