Skip to content

Conversation

@xavierleroy
Copy link
Contributor

@xavierleroy xavierleroy commented Oct 30, 2023

C++ 11 makes it an error to convert automatically from int to bool in some contexts (list initialization). C has no bool type by default, only _Bool, which is not in C++ by default. So we end up with two definitions of Bool_val, one for C and one for C++.

Fixes: #11332

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it does what it says on the tin.

C++ 11 prohibits narrowing conversions from `int` to `bool` in some contexts
(list initialization).
C has no `bool` type by default, only `_Bool`, which is not in C++ by default.
So we end up with two definitions of `Bool_val`, one for C and one for C++.

Fixes: ocaml#11332
@xavierleroy xavierleroy merged commit 14d9ab1 into ocaml:trunk Oct 30, 2023
@xavierleroy xavierleroy deleted the C++bool branch October 30, 2023 13:00
@xavierleroy
Copy link
Contributor Author

Should this be backported to 4.12 LTS ?

@Octachron
Copy link
Member

Octachron commented Oct 30, 2023

This seems worth it to maintain compatibility between 4.14 LTS and OCaml 5 for the FFI headers.

xavierleroy added a commit that referenced this pull request Oct 30, 2023
C++ 11 prohibits narrowing conversions from `int` to `bool` in some contexts
(list initialization).
C has no `bool` type by default, only `_Bool`, which is not in C++ by default.
So we end up with two definitions of `Bool_val`, one for C and one for C++.

Fixes: #11332
(cherry picked from commit 14d9ab1)
@xavierleroy
Copy link
Contributor Author

Cherry-picked on 4.14 branch: c48b55e .

ejgallego pushed a commit to ejgallego/ocaml that referenced this pull request Nov 5, 2025
C++ 11 prohibits narrowing conversions from `int` to `bool` in some contexts
(list initialization).
C has no `bool` type by default, only `_Bool`, which is not in C++ by default.
So we end up with two definitions of `Bool_val`, one for C and one for C++.

Fixes: ocaml#11332
(cherry picked from commit 14d9ab1)
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.

assigning result of Bool_val to bool generates error (when used in C++ context)

3 participants