diff options
author | Brad King <brad.king@kitware.com> | 2022-10-21 14:05:34 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-10-21 14:06:22 (GMT) |
commit | 7c71f9b1e8319f93418bb91dc9fbf8fcdaca8add (patch) | |
tree | c622be9e80894c733d838be2cb37d035233630d7 /Source/Checks | |
parent | 714440fdf2e99cd832570b9cee0a5d57fe225aee (diff) | |
parent | ee9805ccd17670e945e41e62f160bfdd9ad8a386 (diff) | |
download | CMake-7c71f9b1e8319f93418bb91dc9fbf8fcdaca8add.zip CMake-7c71f9b1e8319f93418bb91dc9fbf8fcdaca8add.tar.gz CMake-7c71f9b1e8319f93418bb91dc9fbf8fcdaca8add.tar.bz2 |
Merge topic 'filesystem-path-c++03-abi'
ee9805ccd1 cm/filesystem: Fix crash with pre-C++11 std::string GNU ABI in C++17
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7813
Diffstat (limited to 'Source/Checks')
-rw-r--r-- | Source/Checks/cm_cxx_features.cmake | 4 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_filesystem.cxx | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index c88f5a3..73e7ef2 100644 --- a/Source/Checks/cm_cxx_features.cmake +++ b/Source/Checks/cm_cxx_features.cmake @@ -80,9 +80,7 @@ if(CMake_HAVE_CXX_MAKE_UNIQUE) set(CMake_HAVE_CXX_UNIQUE_PTR 1) endif() cm_check_cxx_feature(unique_ptr) -if (NOT CMAKE_CXX_STANDARD LESS "17" - AND NOT MSYS # FIXME: RunCMake.cmake_path cases crash with MSYS std::filesystem - ) +if (NOT CMAKE_CXX_STANDARD LESS "17") if (NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR) cm_check_cxx_feature(filesystem TRY_RUN) else() diff --git a/Source/Checks/cm_cxx_filesystem.cxx b/Source/Checks/cm_cxx_filesystem.cxx index ae8acc5..732f28f 100644 --- a/Source/Checks/cm_cxx_filesystem.cxx +++ b/Source/Checks/cm_cxx_filesystem.cxx @@ -23,5 +23,16 @@ int main() } #endif + // If std::string is copy-on-write, the std::filesystem::path + // implementation may accidentally trigger a reallocation and compute + // an offset between two allocations, leading to undefined behavior. +#if defined(__GLIBCXX__) && \ + (!defined(_GLIBCXX_USE_CXX11_ABI) || !_GLIBCXX_USE_CXX11_ABI) + std::string p5s1 = "/path"; + std::string p5s2 = std::move(p5s1); + std::filesystem::path p5 = std::string(p5s2); + p5.remove_filename(); +#endif + return 0; } |