Skip to content

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

Merged
gaoxueyu merged 3 commits into
IvorySQL:masterfrom
messere1:fix/issue-1351-gcc14-c23-bool
Jul 21, 2026
Merged

gaoxueyu merged 3 commits into
IvorySQL:masterfrom
messere1:fix/issue-1351-gcc14-c23-bool

Conversation

@messere1

@messere1 messere1 commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

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, so validation fails consistently instead of returning an unexpected value.
    • Improved build compatibility with standard C boolean handling by relying on the standard boolean header and removing the previous custom boolean fallback logic.

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: e71f8372-fa6d-4bdb-aef3-711f8eb6a7a2

📥 Commits

Reviewing files that changed from the base of the PR and between 0b63396 and 733f164.

📒 Files selected for processing (1)
  • src/interfaces/libpq/libpq-fe.h

📝 Walkthrough

Walkthrough

Two build-compatibility fixes update the XML fallback return value to match Datum and make libpq-fe.h use the standard C boolean definitions instead of a custom bool typedef.

Changes

Build Compatibility Fixes

Layer / File(s) Summary
Correct XML fallback return
contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c
ivy_xmlisvalid now returns 0 instead of NULL when XML support is unavailable.
Use standard C boolean definitions
src/interfaces/libpq/libpq-fe.h
Includes <stdbool.h> and removes the custom fallback bool typedef and its preprocessor logic.

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

Possibly related PRs

🚥 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 clearly matches the main fix: GCC 14+ C23 build failures from the bool typedef and NULL-to-Datum return.
Linked Issues check ✅ Passed The changes address #1351 by replacing the custom bool typedef with <stdbool.h> and fixing the Datum fallback return value.
Out of Scope Changes check ✅ Passed The pull request is narrowly focused on the reported build failures and does not introduce unrelated changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@hanjianqiao hanjianqiao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Modification of contrib/ivorysql_ora/src/xml_functions/ora_xml_functions.c is OK.

@hanjianqiao

Copy link
Copy Markdown
Collaborator

@messere1 Thx again for your work. But using standard headers is strongly preferred over custom data types.

Replace the custom bool typedef with <stdbool.h>, as requested in the review of PR IvorySQL#1385.

Assisted-by: OpenAI:gpt-5
@hanjianqiao

Copy link
Copy Markdown
Collaborator

LGTM, ready to merge.

@gaoxueyu
gaoxueyu merged commit f58336f into IvorySQL:master Jul 21, 2026
8 checks passed
hs-liuxh pushed a commit to hs-liuxh/IvorySQL that referenced this pull request Sep 2, 2026
…23-bool

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

(cherry picked from commit f58336f)
hs-liuxh pushed a commit to hs-liuxh/IvorySQL that referenced this pull request Sep 2, 2026
…23-bool

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

(cherry picked from commit f58336f)
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