Hi hackers,

While using an invalid c_args by mistake with clang and meson, I observed the
following:

$ CC="clang" meson setup meson_build -Dc_args="-Wbad"

produces:

meson.build:645:4: ERROR: Problem encountered: C compiler does not support C11

This is misleading: my C compiler does support C11 but the C11 check fails
due to the invalid arg, as stated in meson-log.txt:

"
stderr:
error: unknown warning option '-Wbad' [-Werror,-Wunknown-warning-option]
"

OTOH, providing an invalid CFLAG with autoconf and using clang currently 
produces
warnings like:

"
warning: unknown warning option '-Wbad' [-Wunknown-warning-option]
"

That's perfectly fine and not misleading.

If using gcc instead of clang, then:

1/ with autoconf, we get:

"
checking whether the C compiler works... no
configure: error: in `/home/postgres/postgresql/postgres':
configure: error: C compiler cannot create executables
See `config.log' for more details
"

and in config.log:

"
configure:4028: checking whether the C compiler works
configure:4050: gcc -O0 -Wbad   conftest.c  >&5
gcc: error: unrecognized command-line option '-Wbad'"

That's not misleading.

2/ with meson, we get:

"
$ CC="gcc" meson setup meson_build -Dc_args="-Wbad"

meson.build:9:0: ERROR: Compiler gcc cannot compile programs.
"

That's not misleading.

So it looks like that GCC treats an invalid CFLAG as an error by itself, while
clang only treats it as a warning (unless -Werror=unknown-warning-option is 
present).

Also, it looks like that when using clang, meson injects 
-Werror=unknown-warning-option
into cc.compiles().

This can be confirmed by creating a simple meson.build as:

"
project('test', 'c')
cc = meson.get_compiler('c')
cc.compiles('int main(void){return 0;}', name: 'test probe')
"

and running the compilation with a valid arg:

$ CC=gcc meson setup testbuild  -Dc_args="-Wunused-value"

and check:

$ grep -c unknown-warning-option testbuild/meson-logs/meson-log.txt
0

While (with clang):

$ CC=clang meson setup testbuild  -Dc_args="-Wunused-value"
$ grep -c unknown-warning-option testbuild/meson-logs/meson-log.txt
1

So, PFA, a patch that adds a cc.has_multi_arguments() check before the C11 test 
so
that :

CC="clang" meson setup meson_build -Dc_args="-Wbad"

now produces:

"
Compiler for C supports arguments -Wbad: NO

meson.build:625:2: ERROR: Problem encountered: One or more c_args are not 
supported by clang 21.0.0
"

and does not report wrongly that the C compiler does not support C11 when using
clang with meson (and an invalid c_args).

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
>From 2ae165b91772f2e45f0f9e72a2aeb529a3e03fc0 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <[email protected]>
Date: Wed, 18 Mar 2026 05:53:12 +0000
Subject: [PATCH v1] meson: error about unsupported user-supplied c_args before
 C11 check

When using clang, meson injects -Werror=unknown-warning-option into cc.compiles()
calls. A user-supplied c_args flag unsupported by clang therefore causes the C11
check to fail with the misleading error "C compiler does not support C11".

This commit adds a cc.has_multi_arguments() check before the C11 test to catch
unsupported c_args early.
---
 meson.build | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/meson.build b/meson.build
index 46bd6b1468a..aadaf706e2e 100644
--- a/meson.build
+++ b/meson.build
@@ -620,6 +620,15 @@ dir_doc_extension = dir_doc / 'extension'
 # used, they need to be added to test_c_args as well.
 ###############################################################
 
+# Validate user-supplied c_args early: when using clang, meson injects
+# -Werror=unknown-warning-option into cc.compiles(), so an unsupported
+# flag would cause the C11 check below to fail with a misleading error.
+if not cc.has_multi_arguments(get_option('c_args'))
+  error('One or more c_args are not supported by @0@ @1@'.format(
+    cc.get_id(),
+    cc.version()))
+endif
+
 # Do we need an option to enable C11?
 c11_test = '''
 #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
-- 
2.34.1

Reply via email to