Merge topic 'revert-CheckCompilerFlag-clang-argument-unused' into release-3.26

97fcd3bd30 CheckCompilerFlag: Revert 'Match the Clang "argument unused" output ...'

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: scivision <michael@scivision.dev>
Merge-request: !8322
diff --git a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
index cd978d5..bda1d71 100644
--- a/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
+++ b/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake
@@ -12,7 +12,6 @@
     FAIL_REGEX "switch .* is no longer supported"          # GNU
     FAIL_REGEX "unknown .*option"                          # Clang
     FAIL_REGEX "optimization flag .* not supported"        # Clang
-    FAIL_REGEX "argument unused during compilation: .*"    # Clang
     FAIL_REGEX "unknown argument ignored"                  # Clang (cl)
     FAIL_REGEX "ignoring unknown option"                   # MSVC, Intel
     FAIL_REGEX "warning D9002"                             # MSVC, any lang
diff --git a/Modules/Internal/CMakeTryCompilerOrLinkerFlag.cmake b/Modules/Internal/CMakeTryCompilerOrLinkerFlag.cmake
index ff8908b..b671b4a 100644
--- a/Modules/Internal/CMakeTryCompilerOrLinkerFlag.cmake
+++ b/Modules/Internal/CMakeTryCompilerOrLinkerFlag.cmake
@@ -69,6 +69,7 @@
     set (CCCF_COMMAND_PATTERN "<FLAG> -o <OUTPUT> <SOURCE>")
   endif()
 
+  list (APPEND CCCF_FAIL_REGEX "argument unused during compilation") # clang
   if (check_lang STREQUAL "C")
     list(APPEND CCCF_FAIL_REGEX
       "command line option .* is valid for .* but not for C") # GNU
diff --git a/Modules/Internal/CheckFlagCommonConfig.cmake b/Modules/Internal/CheckFlagCommonConfig.cmake
index 61eada2..f8481cd 100644
--- a/Modules/Internal/CheckFlagCommonConfig.cmake
+++ b/Modules/Internal/CheckFlagCommonConfig.cmake
@@ -22,26 +22,30 @@
       FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+")
   elseif("${_LANG}" STREQUAL "CUDA")
     set(${_SRC} "__host__ int main() { return 0; }")
-    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+") # Host GNU
+    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU
+      FAIL_REGEX "argument unused during compilation: .*") # Clang
   elseif("${_LANG}" STREQUAL "Fortran")
     set(${_SRC} "       program test\n       stop\n       end program")
     set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran")
   elseif("${_LANG}" STREQUAL "HIP")
     set(${_SRC} "__host__ int main() { return 0; }")
+    set(${_PATTERNS} FAIL_REGEX "argument unused during compilation: .*") # Clang
   elseif("${_LANG}" STREQUAL "OBJC")
     set(${_SRC} [=[
       #ifndef __OBJC__
       #  error "Not an Objective-C compiler"
       #endif
       int main(void) { return 0; }]=])
-    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C") # GNU
+    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU
+      FAIL_REGEX "argument unused during compilation: .*") # Clang
   elseif("${_LANG}" STREQUAL "OBJCXX")
     set(${_SRC} [=[
       #ifndef __OBJC__
       #  error "Not an Objective-C++ compiler"
       #endif
       int main(void) { return 0; }]=])
-    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+") # GNU
+    set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU
+      FAIL_REGEX "argument unused during compilation: .*") # Clang
   elseif("${_LANG}" STREQUAL "ISPC")
     set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }")
   elseif("${_LANG}" STREQUAL "Swift")
diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagC.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagC.cmake
index 276158c..64a961e 100644
--- a/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagC.cmake
+++ b/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagC.cmake
@@ -18,6 +18,15 @@
   if(NOT SHOULD_WORK)
     message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-x c' check failed")
   endif()
+
+  block()
+    # Test tolerating a flag that is not used when driving the linker.
+    string(APPEND CMAKE_C_FLAGS " -nostdinc")
+    check_compiler_flag(C "-x c" SHOULD_WORK_NOSTDINC)
+    if(NOT SHOULD_WORK_NOSTDINC)
+      message(SEND_ERROR "${CMAKE_C_COMPILER_ID} compiler flag '-x c -nostdinc' check failed")
+    endif()
+  endblock()
 endif()
 
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU") # LCC C compiler silently ignore -frtti instead of failing, so skip it here.
diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagCXX.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagCXX.cmake
index dec31ec..0026a2a 100644
--- a/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagCXX.cmake
+++ b/Tests/RunCMake/CheckCompilerFlag/CheckCompilerFlagCXX.cmake
@@ -18,6 +18,15 @@
   if(NOT SHOULD_WORK)
     message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed")
   endif()
+
+  block()
+    # Test tolerating a flag that is not used when driving the linker.
+    string(APPEND CMAKE_CXX_FLAGS " -nostdinc++")
+    check_compiler_flag(CXX "-x c++" SHOULD_WORK_NOSTDINCXX)
+    if(NOT SHOULD_WORK_NOSTDINCXX)
+      message(SEND_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++ -nostdinc++' check failed")
+    endif()
+  endblock()
 endif()
 
 if(NOT "$ENV{LC_ALL}" STREQUAL "BAD")