Skip to content

Commit 16ce422

Browse files
committed
build: explicit_this enabled for AppleClang 17 and MSVC 19.32
Both compilers do not implement the feature test macro, but they do implement `explicit_this`, as mentioned in their corresponding release notes: - https://developer.apple.com/documentation/xcode-release-notes/xcode-16_3-release-notes - https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.2 Resolves #722.
1 parent 54045e2 commit 16ce422

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

conanfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def _feature_compatibility(self):
119119
"compiler": {
120120
"gcc": "14",
121121
"clang": "18",
122-
"apple-clang": "",
123-
"msvc": "195",
122+
"apple-clang": "17",
123+
"msvc": "194",
124124
},
125125
},
126126
}

docs/getting_started/cpp_compiler_support.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ C++ feature:
1919
| **`std::format`** | 20 | 13+ | 17+ | 16+ | 194+ |
2020
| **C++ modules** | 20 | None | 17+ | None | None |
2121
| **`import std;`** | 23 | None | 18+ | None | None |
22-
| **Explicit `this` parameter** | 23 | 14+ | 18+ | None | 195+ |
22+
| **Explicit `this` parameter** | 23 | 14+ | 18+ | 17+ | 194+ |
2323

2424
??? note "clang-19 unfixable bug"
2525

@@ -97,6 +97,8 @@ C++ feature:
9797
- To write code with wide compatibility
9898
a [dedicated macro may be used](../users_guide/use_cases/wide_compatibility.md#QUANTITY_SPEC).
9999
- Tested with `__cpp_explicit_this_parameter` [feature test macro](https://en.cppreference.com/w/cpp/feature_test).
100+
- Note that some compiler versions do not implement this macro even though they do support the
101+
feature well enough. In such cases, compilation with explicit `this` is enforced.
100102
- Related build options:
101103
- Conan: [no_crtp](installation_and_usage.md#no_crtp)
102104
- CMake: [MP_UNITS_API_NO_CRTP](installation_and_usage.md#MP_UNITS_API_NO_CRTP)

src/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,21 @@ endif()
6767

6868
# clang++-18 supports explicit `this` parameter
6969
# https://github.com/llvm/llvm-project/issues/82780
70-
if(NOT ${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED
71-
AND CMAKE_CXX_STANDARD GREATER_EQUAL 23
72-
AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
73-
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18"
74-
)
75-
message(STATUS "Clang 18+ detected, overriding `no CRTP` support")
76-
set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON)
70+
# AppleClang 17 also supports explicit `this` parameter (feature check macro unimplemented)
71+
# https://developer.apple.com/documentation/xcode-release-notes/xcode-16_3-release-notes
72+
# MSVC 19.32 also supports explicit `this` parameter (feature check macro unimplemented in this version)
73+
# https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.2
74+
if(NOT ${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED AND CMAKE_CXX_STANDARD GREATER_EQUAL 23)
75+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18")
76+
message(STATUS "Clang 18+ detected, overriding `no CRTP` support")
77+
set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON)
78+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17")
79+
message(STATUS "AppleClang 17+ detected, overriding `no CRTP` support")
80+
set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON)
81+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.32")
82+
message(STATUS "MSVC 19.32+ detected, overriding `no CRTP` support")
83+
set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON)
84+
endif()
7785
endif()
7886

7987
# project API settings

0 commit comments

Comments
 (0)