From 1560e367afc7d95ded40f1c67e559ac60c4c49cc Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Sun, 2 Oct 2022 13:17:04 +0200 Subject: codegen: Add glib.h include for TRUE/FALSE literal Fixes https://gitlab.gnome.org/GNOME/vala/issues/1364 --- codegen/valaccodebasemodule.vala | 1 + tests/Makefile.am | 1 + tests/basic-types/boolean-literal.c-expected | 23 +++++++++++++++++++++++ tests/basic-types/boolean-literal.vala | 5 +++++ tests/parser/with-embedded.c-expected | 2 +- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/basic-types/boolean-literal.c-expected create mode 100644 tests/basic-types/boolean-literal.vala diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index fb323e28e..ccaf79547 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -6862,6 +6862,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { public CCodeExpression get_boolean_cconstant (bool b) { if (context.profile == Profile.GOBJECT) { + cfile.add_include ("glib.h"); return new CCodeConstant (b ? "TRUE" : "FALSE"); } else { cfile.add_include ("stdbool.h"); diff --git a/tests/Makefile.am b/tests/Makefile.am index dd6f39684..6a2acf56c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -49,6 +49,7 @@ TESTS = \ basic-types/floats.vala \ basic-types/floats-boxed-cast.vala \ basic-types/boolean.vala \ + basic-types/boolean-literal.vala \ basic-types/custom-types.vala \ basic-types/default-gtype.vala \ basic-types/strings.vala \ diff --git a/tests/basic-types/boolean-literal.c-expected b/tests/basic-types/boolean-literal.c-expected new file mode 100644 index 000000000..89441a6c1 --- /dev/null +++ b/tests/basic-types/boolean-literal.c-expected @@ -0,0 +1,23 @@ +/* basic_types_boolean_literal.c generated by valac, the Vala compiler + * generated from basic_types_boolean_literal.vala, do not modify */ + +#include + +static void _vala_main (void); + +static void +_vala_main (void) +{ + if (TRUE) { + return; + } +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + diff --git a/tests/basic-types/boolean-literal.vala b/tests/basic-types/boolean-literal.vala new file mode 100644 index 000000000..be7d379e7 --- /dev/null +++ b/tests/basic-types/boolean-literal.vala @@ -0,0 +1,5 @@ +void main () { + if (true) { + return; + } +} diff --git a/tests/parser/with-embedded.c-expected b/tests/parser/with-embedded.c-expected index d825c379f..29935c99e 100644 --- a/tests/parser/with-embedded.c-expected +++ b/tests/parser/with-embedded.c-expected @@ -1,9 +1,9 @@ /* parser_with_embedded.c generated by valac, the Vala compiler * generated from parser_with_embedded.vala, do not modify */ +#include #include #include -#include #define _g_free0(var) (var = (g_free (var), NULL)) #define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); -- cgit v1.2.1