diff options
author | Brad King <brad.king@kitware.com> | 2022-10-20 23:03:19 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-10-20 23:03:19 (GMT) |
commit | 199b3e580d08da2b883d3c5c173b9c59abbc1184 (patch) | |
tree | 402a9d03107dee1098eb96d58357bbaeff63aec9 | |
parent | 96172ba2d18b98b2a5b651dee5326d7298c5891c (diff) | |
parent | ee9805ccd17670e945e41e62f160bfdd9ad8a386 (diff) | |
download | CMake-199b3e580d08da2b883d3c5c173b9c59abbc1184.zip CMake-199b3e580d08da2b883d3c5c173b9c59abbc1184.tar.gz CMake-199b3e580d08da2b883d3c5c173b9c59abbc1184.tar.bz2 |
Merge branch 'filesystem-path-c++03-abi' into release-3.23
Merge-request: !7813
-rw-r--r-- | Source/Checks/cm_cxx_features.cmake | 4 | ||||
-rw-r--r-- | Source/Checks/cm_cxx_filesystem.cxx | 11 | ||||
-rw-r--r-- | Utilities/std/cm/filesystem | 16 |
3 files changed, 18 insertions, 13 deletions
diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake index f20572e..7917d41 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; } diff --git a/Utilities/std/cm/filesystem b/Utilities/std/cm/filesystem index ce52fbf..b1cb366 100644 --- a/Utilities/std/cm/filesystem +++ b/Utilities/std/cm/filesystem @@ -809,13 +809,11 @@ public: path& remove_filename() { -# if defined(__CYGWIN__) - // FIXME: Avoid crash due to CYGWIN/MSYS bug(?). See CMake Issue 22090. - static_cast<void>(this->path_.data()); -# endif auto fname = this->get_filename(); if (!fname.empty()) { - this->path_.erase(fname.data() - this->path_.data()); + this->path_.erase(fname.data() - + // Avoid C++17 non-const .data() that may reallocate. + static_cast<path_type const&>(this->path_).data()); } return *this; } @@ -829,13 +827,11 @@ public: path& replace_extension(const path& replacement = path()) { -# if defined(__CYGWIN__) - // FIXME: Avoid crash due to CYGWIN/MSYS bug(?). See CMake Issue 22090. - static_cast<void>(this->path_.data()); -# endif auto ext = this->get_filename_fragment(filename_fragment::extension); if (!ext.empty()) { - this->path_.erase(ext.data() - this->path_.data()); + this->path_.erase(ext.data() - + // Avoid C++17 non-const .data() that may reallocate. + static_cast<path_type const&>(this->path_).data()); } if (!replacement.path_.empty()) { if (replacement.path_[0] != '.') { |