]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
build: replace `-pedantic` with `-Wpedantic` when supported
authorViktor Szakats <commit@vsz.me>
Wed, 17 Dec 2025 14:13:12 +0000 (15:13 +0100)
committerViktor Szakats <commit@vsz.me>
Thu, 18 Dec 2025 00:35:59 +0000 (01:35 +0100)
To use the modern form when possible. The modern option also allows
using the `no-` prefix to disable.

Supported by: gcc 4.8+, clang 3.2+ (= appleclang 4.2+)

This also automatically changes `-clang:-pedantic` to `-Wpedantic` in
clang-cl builds.

Refs:
https://github.com/llvm/llvm-project/commit/9877f689f282b19ca697aa8c6fecd752a84dbddd
https://gcc.gnu.org/onlinedocs/gcc-4.8.5/gcc/Warning-Options.html

Closes #20010

CMake/PickyWarnings.cmake
m4/curl-compilers.m4

index 00451f7480bd4e1d0092d10c9ff3abde0afc5ee8..5e643c5866f9a0be34a0bffefbcf64a9e30e929a 100644 (file)
@@ -75,9 +75,15 @@ if(PICKY_COMPILER)
       set(_picky_enable "-W")
     endif()
 
-    list(APPEND _picky_enable
-      -Wall -pedantic
-    )
+    list(APPEND _picky_enable "-Wall")
+
+    if((CMAKE_C_COMPILER_ID STREQUAL "Clang"      AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.2) OR
+       (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2) OR
+       CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.8)
+      list(APPEND _picky_enable "-Wpedantic")  # clang  3.2  gcc  4.8  appleclang  4.2
+    else()
+      list(APPEND _picky_enable "-pedantic")
+    endif()
 
     # ----------------------------------
     # Add new options here, if in doubt:
index 7b4b5bed2318ccc2e3cae7b4224b597e304e45a2..ff43f67f9914577ae20de900c6d7b687abbed84a 100644 (file)
@@ -796,7 +796,11 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
       CLANG|APPLECLANG)
         #
         if test "$want_warnings" = "yes"; then
-          tmp_CFLAGS="$tmp_CFLAGS -pedantic"
+          if test "$compiler_num" -ge "302"; then
+            CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pedantic])
+          else
+            tmp_CFLAGS="$tmp_CFLAGS -pedantic"
+          fi
           CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [all extra])
           CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pointer-arith write-strings])
           CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [shadow])
@@ -974,8 +978,12 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
           dnl Do not enable -pedantic when cross-compiling with a gcc older
           dnl than 3.0, to avoid warnings from third party system headers.
           if test "$cross_compiling" != "yes" ||
-            test "$compiler_num" -ge "300"; then
-            tmp_CFLAGS="$tmp_CFLAGS -pedantic"
+             test "$compiler_num" -ge "300"; then
+            if test "$compiler_num" -ge "408"; then
+              CURL_ADD_COMPILER_WARNINGS([tmp_CFLAGS], [pedantic])
+            else
+              tmp_CFLAGS="$tmp_CFLAGS -pedantic"
+            fi
           fi
           #
           dnl Set of options we believe *ALL* gcc versions support: