Skip to content

Commit d50b31b

Browse files
committed
Clang: For MSVC ABI do not use modes older than C++14
Since commit d44c0db (clang: setup correct configuration in gnu mode, 2019-02-20, v3.15.0-rc1~41^2~5) we support the GNU-like Clang that targets the MSVC ABI. However, Clang cannot compile with the MSVC standard library unless it runs in a mode aware of C++14 (since MSVC itself does not even have a lower mode). When `CMAKE_CXX_STANDARD` is set to 98 or 11, use C++14 anyway. Since Clang's default mode is aware of C++14, another option is to not add any flags for 98 or 11. However, if a future Clang version ever defaults to a higher C++ standard, setting the standard to 98 or 11 should at least not use a mode higher than 14. Also revert test updates from commit 4819ff9 (Tests: fix failures with gnu mode clang on windows, 2019-03-21, v3.15.0-rc1~41^2~3) that were meant to work around the standard selection problem. Fixes: #19496
1 parent 79bcf4e commit d50b31b

File tree

7 files changed

+15
-30
lines changed

7 files changed

+15
-30
lines changed

Modules/Compiler/Clang-CXX.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ if("x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
5858
unset(_clang_version_std17)
5959

6060
if("x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
61+
# The MSVC standard library requires C++14, and MSVC itself has no
62+
# notion of operating in a mode not aware of at least that standard.
63+
set(CMAKE_CXX98_STANDARD_COMPILE_OPTION "-std=c++14")
64+
set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION "-std=gnu++14")
65+
set(CMAKE_CXX11_STANDARD_COMPILE_OPTION "-std=c++14")
66+
set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION "-std=gnu++14")
67+
6168
# This clang++ is missing some features because of MSVC compatibility.
6269
unset(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT)
6370
unset(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT)

Tests/AliasTarget/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD 98)
77
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
88
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
99
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
10-
set(CMAKE_CXX_STANDARD 14)
10+
set(CMAKE_CXX_STANDARD 11)
1111
endif()
1212

1313
add_library(foo SHARED empty.cpp)

Tests/Complex/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,11 +446,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
446446
set(CMAKE_CXX_STANDARD 11)
447447
endif()
448448

449-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
450-
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
451-
set(CMAKE_CXX_STANDARD 14)
452-
endif()
453-
454449
#
455450
# Create the libs and the main exe
456451
#

Tests/ComplexOneConfig/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
403403
set(CMAKE_CXX_STANDARD 11)
404404
endif()
405405

406-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
407-
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
408-
set(CMAKE_CXX_STANDARD 14)
409-
endif()
410-
411406
#
412407
# Create the libs and the main exe
413408
#

Tests/Module/WriteCompilerDetectionHeader/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ endif()
133133

134134
# for msvc the compiler version determines which c++11 features are available.
135135
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"
136-
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
137-
AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
138-
AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xMSVC" ))
136+
OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
139137
if(";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ";cxx_delegating_constructors;")
140138
list(APPEND true_defs EXPECTED_COMPILER_CXX_DELEGATING_CONSTRUCTORS)
141139
list(APPEND true_defs EXPECTED_COMPILER_CXX_VARIADIC_TEMPLATES)

Tests/Plugin/CMakeLists.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ project(Plugin)
55
# We need proper C++98 support from the compiler
66
set(CMAKE_CXX_STANDARD 98)
77

8-
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
9-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
10-
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
11-
set(CMAKE_CXX_STANDARD 11)
12-
endif()
13-
14-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
15-
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
16-
set(CMAKE_CXX_STANDARD 14)
17-
endif()
18-
198
# Test per-target output directory properties.
209
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/bin)
2110
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Plugin_BINARY_DIR}/lib/plugin)
@@ -40,6 +29,12 @@ include_directories(
4029
${Plugin_SOURCE_DIR}/include
4130
)
4231

32+
# Clang/C2 in C++98 mode cannot properly handle some of MSVC headers
33+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
34+
CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC")
35+
set(CMAKE_CXX_STANDARD 11)
36+
endif()
37+
4338
# Create an executable that exports an API for use by plugins.
4439
add_executable(example_exe src/example_exe.cxx)
4540
set_target_properties(example_exe PROPERTIES

Tests/RunCMake/GenerateExportHeader/GEH.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
5151
set(CMAKE_CXX_STANDARD 11)
5252
endif()
5353

54-
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
55-
CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
56-
set(CMAKE_CXX_STANDARD 14)
57-
endif()
58-
5954
add_subdirectory(lib_shared_and_static)
6055

6156
if(CMAKE_SYSTEM_NAME MATCHES "AIX" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU"

0 commit comments

Comments
 (0)