From 16ce422cdf0655ad489b070c9fca426efd359b6c Mon Sep 17 00:00:00 2001 From: Alexandros Theodotou Date: Wed, 24 Sep 2025 19:54:44 +0900 Subject: [PATCH] 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. --- conanfile.py | 4 ++-- docs/getting_started/cpp_compiler_support.md | 4 +++- src/CMakeLists.txt | 22 +++++++++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/conanfile.py b/conanfile.py index f375adce1..61f536d77 100644 --- a/conanfile.py +++ b/conanfile.py @@ -119,8 +119,8 @@ def _feature_compatibility(self): "compiler": { "gcc": "14", "clang": "18", - "apple-clang": "", - "msvc": "195", + "apple-clang": "17", + "msvc": "194", }, }, } diff --git a/docs/getting_started/cpp_compiler_support.md b/docs/getting_started/cpp_compiler_support.md index a8a26145e..bbd8c615b 100644 --- a/docs/getting_started/cpp_compiler_support.md +++ b/docs/getting_started/cpp_compiler_support.md @@ -19,7 +19,7 @@ C++ feature: | **`std::format`** | 20 | 13+ | 17+ | 16+ | 194+ | | **C++ modules** | 20 | None | 17+ | None | None | | **`import std;`** | 23 | None | 18+ | None | None | -| **Explicit `this` parameter** | 23 | 14+ | 18+ | None | 195+ | +| **Explicit `this` parameter** | 23 | 14+ | 18+ | 17+ | 194+ | ??? note "clang-19 unfixable bug" @@ -97,6 +97,8 @@ C++ feature: - To write code with wide compatibility a [dedicated macro may be used](../users_guide/use_cases/wide_compatibility.md#QUANTITY_SPEC). - Tested with `__cpp_explicit_this_parameter` [feature test macro](https://en.cppreference.com/w/cpp/feature_test). + - Note that some compiler versions do not implement this macro even though they do support the + feature well enough. In such cases, compilation with explicit `this` is enforced. - Related build options: - Conan: [no_crtp](installation_and_usage.md#no_crtp) - CMake: [MP_UNITS_API_NO_CRTP](installation_and_usage.md#MP_UNITS_API_NO_CRTP) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1a0d7464..5f48082c8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,13 +67,21 @@ endif() # clang++-18 supports explicit `this` parameter # https://github.com/llvm/llvm-project/issues/82780 -if(NOT ${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED - AND CMAKE_CXX_STANDARD GREATER_EQUAL 23 - AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" - AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18" -) - message(STATUS "Clang 18+ detected, overriding `no CRTP` support") - set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON) +# AppleClang 17 also supports explicit `this` parameter (feature check macro unimplemented) +# https://developer.apple.com/documentation/xcode-release-notes/xcode-16_3-release-notes +# MSVC 19.32 also supports explicit `this` parameter (feature check macro unimplemented in this version) +# https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.2 +if(NOT ${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED AND CMAKE_CXX_STANDARD GREATER_EQUAL 23) + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "18") + message(STATUS "Clang 18+ detected, overriding `no CRTP` support") + set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "17") + message(STATUS "AppleClang 17+ detected, overriding `no CRTP` support") + set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "19.32") + message(STATUS "MSVC 19.32+ detected, overriding `no CRTP` support") + set(${projectPrefix}EXPLICIT_THIS_PARAMETER_SUPPORTED ON) + endif() endif() # project API settings