mailing list of musl libc
 help / color / mirror / code / Atom feed
* stdbool.h does not define _Bool when included by C++ code
@ 2017-07-28 10:21 Michael Clark
  2017-07-28 13:01 ` Rich Felker
  2017-07-31  9:18 ` Szabolcs Nagy
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Clark @ 2017-07-28 10:21 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

Hi,

I noticed an issue with the musl headers when installing compiler-explorer for RISC-V. Try compiling this code with g++ and musl's stdbool.h

	- https://cx.rv8.io/g/Bc3AwY <https://cx.rv8.io/>

Compiler explorer uses the C++ front-end to the compiler by default

It seems the musl stdbool.h defines bool in terms of _Bool for C, but does not define _Bool in terms of bool for C++.

The gcc stdbool.h header handles both conditions and when included by C++ code it has #define _Bool bool but notes that it is a GNU extension.

My workaround was to delete the musl stdbool.h so that the GCC version is included, but it seems the header could work for C code passed through the C++ front-end with a small patch (attached). The other musl headers seem to support C++, so I think it might be nice to fix stdbool.h for C code compiled through the C++ front-end. Of course C++ code needs casts on malloc and there are several other differences such as new reserved words, however for the most part, a lot of C code can compile using the C++ front-end.

Michael


[-- Attachment #2.1: Type: text/html, Size: 1767 bytes --]

[-- Attachment #2.2: musl-stdbool-cplusplus.patch --]
[-- Type: application/octet-stream, Size: 267 bytes --]

diff --git a/include/stdbool.h b/include/stdbool.h
index a9d7ab7..06742f9 100644
--- a/include/stdbool.h
+++ b/include/stdbool.h
@@ -7,6 +7,10 @@
 #define false 0
 #define bool _Bool
 
+#else
+
+#define _Bool bool
+
 #endif
 
 #define __bool_true_false_are_defined 1

[-- Attachment #2.3: Type: text/html, Size: 233 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-08-01  7:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28 10:21 stdbool.h does not define _Bool when included by C++ code Michael Clark
2017-07-28 13:01 ` Rich Felker
2017-07-31  9:18 ` Szabolcs Nagy
2017-07-31  9:46   ` Jens Gustedt
2017-07-31 21:06     ` Michael Clark
2017-08-01  1:31       ` Rich Felker
2017-08-01  7:24         ` Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).