From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 4CC893AA980E; Fri, 18 Jun 2021 14:43:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CC893AA980E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r9-9593] libstdc++: Fix filesystem::path constraints for volatile [PR 100630] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: 91d29ed563bd7e787921f997ea2f80cd87ee59b2 X-Git-Newrev: 3c805829c9023da48db6d636221fd79612dff7ea Message-Id: <20210618144345.4CC893AA980E@sourceware.org> Date: Fri, 18 Jun 2021 14:43:45 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jun 2021 14:43:45 -0000 https://gcc.gnu.org/g:3c805829c9023da48db6d636221fd79612dff7ea commit r9-9593-g3c805829c9023da48db6d636221fd79612dff7ea Author: Jonathan Wakely Date: Mon May 17 11:54:06 2021 +0100 libstdc++: Fix filesystem::path constraints for volatile [PR 100630] The constraint check for filesystem::path construction uses decltype(__is_path_src(declval())) which mean it considers conversion from an rvalue. When Source is a volatile-qualified type it cannot use is_path_src(const Unknown&) because a const lvalue reference can only bind to a non-volatile rvalue. Since the relevant path members all have a const Source& parameter, the constraint should be defined in terms of declval(), not declval(). This avoids the problem of volatile-qualified rvalues, because we no longer use an rvalue at all. libstdc++-v3/ChangeLog: PR libstdc++/100630 * include/bits/fs_path.h (__is_constructible_from): Test construction from a const lvalue, not an rvalue. * include/experimental/bits/fs_path.h (__is_constructible_from): Likewise. * testsuite/27_io/filesystem/path/construct/100630.cc: New test. * testsuite/experimental/filesystem/path/construct/100630.cc: New test. (cherry picked from commit 4cd69a5a0dd31bc6fdef1bbabc8d6d1416014ea1) Diff: --- libstdc++-v3/include/bits/fs_path.h | 2 +- libstdc++-v3/include/experimental/bits/fs_path.h | 2 +- .../testsuite/27_io/filesystem/path/construct/100630.cc | 14 ++++++++++++++ .../experimental/filesystem/path/construct/100630.cc | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 13eb18c0652..8b801c6787c 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -110,7 +110,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 template struct __constructible_from<_Source, void> - : decltype(__is_path_src(std::declval<_Source>(), 0)) + : decltype(__is_path_src(std::declval(), 0)) { }; template diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 33a415645d9..ba12b2f1734 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -125,7 +125,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 template struct __constructible_from<_Source, void> - : decltype(__is_path_src(std::declval<_Source>(), 0)) + : decltype(__is_path_src(std::declval(), 0)) { }; template + +void f(bool) { } +void f(const std::filesystem::path&) { } + +void +test_100630() +{ + volatile bool b = true; + f(b); +} diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc new file mode 100644 index 00000000000..b2428ff74cf --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } +// { dg-require-filesystem-ts "" } + +#include + +void f(bool) { } +void f(const std::experimental::filesystem::path&) { } + +void +test_100630() +{ + volatile bool b = true; + f(b); +}