Skip to content

Fix build failure with GCC 14+ (C23 bool keyword and -Wint-conversion)#1385

Open
messere1 wants to merge 1 commit into
IvorySQL:masterfrom
messere1:fix/issue-1351-gcc14-c23-bool
Open

Fix build failure with GCC 14+ (C23 bool keyword and -Wint-conversion)#1385
messere1 wants to merge 1 commit into
IvorySQL:masterfrom
messere1:fix/issue-1351-gcc14-c23-bool

Conversation

@messere1

@messere1 messere1 commented Jul 9, 2026

Copy link
Copy Markdown

Related Issue

Fixes #1351

Motivation

GCC 14 and 15 default to -std=gnu23, where bool, true, and false are C language keywords. This breaks the IvorySQL build in two places with IvorySQL-specific (non-upstream) code:

Error 1 — src/interfaces/libpq/libpq-fe.h:79:

libpq-fe.h:79:23: error: 'bool' cannot be defined via 'typedef'
   79 | typedef unsigned char bool;
      |                       ^~~~
libpq-fe.h:79:23: note: 'bool' is a keyword with '-std=c23' onwards

The existing guard #if !(defined(true) && defined(false)) is insufficient under C23: true/false may not be defined as macros even though bool is a built-in keyword, so the typedef is still emitted and fails.

Error 2 — contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c:2469:

ora_xml_functions.c:2469:16: error: returning 'void *' from a function with return type 'Datum' {aka 'long unsigned int'} makes integer from pointer without a cast [-Wint-conversion]
 2469 |         return NULL;
      |                ^~~~

ivy_xmlisvalid() is declared PG_FUNCTION_INFO_V1 returning Datum, but its #else (no libxml) fallback did return NULL;. GCC 14 promotes -Wint-conversion to an error by default.

Note: The uuid-ossp errors also shown in the issue are tracked separately in #979 and are not addressed here.

Changes

  1. src/interfaces/libpq/libpq-fe.h — Extend the guard so the typedef unsigned char bool; is skipped under C23 (__STDC_VERSION__ >= 202311L) and C++ (__cplusplus), mirroring the pattern already used in src/include/c.h:

    #if !defined(__cplusplus) && !(defined(true) && defined(false)) && \
        !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
    typedef unsigned char bool;
    #endif
  2. contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c — In ivy_xmlisvalid(), replace return NULL; with return 0; in the !USE_LIBXML fallback, matching the upstream PostgreSQL src/backend/utils/adt/xml.c convention for Datum-returning SQL functions.

How Verified

  • Code review confirms both changes follow established PostgreSQL/IvorySQL patterns (c.h C23 guard; xml.c return 0 fallback).
  • Cannot compile-test GCC 14+ from the current Windows environment; CI on this PR (ubuntu-latest with recent GCC) will validate. The fix is minimal and mechanical.
  • The change is backward-compatible: under C11/C17 (__STDC_VERSION__ < 202311L) the original typedef behavior is preserved exactly.

Summary by CodeRabbit

  • Bug Fixes
    • Improved XML validation behavior when XML support is unavailable, returning a clearer failure result instead of an unexpected value.
    • Enhanced compatibility with newer C language versions and C++ builds, reducing build issues related to boolean type handling.

GCC 14 and 15 default to -std=gnu23, where 'bool' is a keyword.  This
causes two compile errors in IvorySQL-specific code:

1. src/interfaces/libpq/libpq-fe.h defines 'typedef unsigned char bool'.
   The existing guard '#if !(defined(true) && defined(false))' is not
   sufficient under C23, because true/false may not be defined as macros
   even though bool is a built-in keyword.  Add a check for __STDC_VERSION__
   >= 202311L (and __cplusplus) to skip the typedef, mirroring the pattern
   used in src/include/c.h.

2. contrib/ivorysql_ora/.../ora_xml_functions.c: ivy_xmlisvalid() returns
   Datum but the !USE_LIBXML fallback did 'return NULL'.  With GCC 14's
   -Wint-conversion promoted to error, this fails.  Replace with 'return 0'
   to match the upstream PostgreSQL xml.c pattern.

Fixes IvorySQL#1351.
Copilot AI review requested due to automatic review settings July 9, 2026 09:02
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2ac5d078-21c8-4325-a296-0f3dd22dfd26

📥 Commits

Reviewing files that changed from the base of the PR and between 7fb2571 and 0b63396.

📒 Files selected for processing (2)
  • contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c
  • src/interfaces/libpq/libpq-fe.h

📝 Walkthrough

Walkthrough

Two independent build-compatibility fixes: the fallback return in ivy_xmlisvalid now returns 0 instead of NULL to match its Datum return type, and the libpq-fe.h fallback bool typedef guard now excludes C++ and C23-capable compilers to avoid redefinition errors.

Changes

C23 Build Compatibility Fixes

Layer / File(s) Summary
Fix Datum return type mismatch
contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c
ivy_xmlisvalid's non-USE_LIBXML fallback now returns 0 instead of NULL, fixing an integer-from-pointer conversion error since the function returns Datum.
Guard bool typedef for C23/C++
src/interfaces/libpq/libpq-fe.h
The preprocessor condition for the fallback typedef unsigned char bool; now also excludes __cplusplus and __STDC_VERSION__ >= 202311L, preventing redefinition errors on C23-capable compilers.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • IvorySQL/IvorySQL#720: Prior PR that added the ivy_xmlisvalid fallback logic in the same function/module now modified here.

Suggested reviewers: yuanyl630

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the GCC 14+/C23 build fix and the two code paths changed.
Linked Issues check ✅ Passed The PR addresses #1351 by guarding the bool typedef in C23/C++ and fixing the Datum return in ivy_xmlisvalid.
Out of Scope Changes check ✅ Passed All changes align with the reported GCC 14+/C23 build failure and no unrelated modifications are present.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes IvorySQL build failures with GCC 14+ (defaulting to -std=gnu23) by avoiding a C23/C++-conflicting bool typedef in libpq-fe.h and correcting a Datum-returning SQL function fallback that previously returned NULL (pointer) instead of an integer Datum.

Changes:

  • Skip typedef unsigned char bool; in src/interfaces/libpq/libpq-fe.h when compiling as C++ or C23 (__STDC_VERSION__ >= 202311L), preventing GCC 14+ errors where bool is a keyword.
  • Replace return NULL; with return 0; in the !USE_LIBXML fallback path of ivy_xmlisvalid() to avoid -Wint-conversion errors and match existing NO_XML_SUPPORT(); return 0; conventions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/interfaces/libpq/libpq-fe.h Extends the bool typedef guard to avoid redefining bool under C23 and C++.
contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c Fixes ivy_xmlisvalid() fallback to return a valid Datum (0) after NO_XML_SUPPORT().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bigplaice

Copy link
Copy Markdown
Collaborator

@hanjianqiao please follow up this pr.

@hanjianqiao

Copy link
Copy Markdown
Collaborator

@messere1 Welcome to contribute to the IvorySQL community! The regression checks has started and we will review the code soon.

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.

Build failure on GCC 14+ due to 'bool' typedef redefinition (requires CFLAGS="-std=gnu11")

5 participants