* [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630]
@ 2021-05-17 14:02 Jonathan Wakely
2021-05-17 14:25 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2021-05-17 14:02 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]
The constraint check for filesystem::path construction uses
decltype(__is_path_src(declval<Source>())) 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<const Source&>(),
not declval<Source>(). 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.
Tested x86_64-linux, pushed to gcc-10 (this isn't needed for gcc-11 or
trunk, but I also plan to backport it to gcc-9).
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3468 bytes --]
commit 4cd69a5a0dd31bc6fdef1bbabc8d6d1416014ea1
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon May 17 11:54:06 2021
libstdc++: Fix filesystem::path constraints for volatile [PR 100630]
The constraint check for filesystem::path construction uses
decltype(__is_path_src(declval<Source>())) 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<const Source&>(),
not declval<Source>(). 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.
diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 3d341916db5..6e0a85417cc 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -116,7 +116,7 @@ namespace __detail
template<typename _Source>
struct __constructible_from<_Source, void>
- : decltype(__is_path_src(std::declval<_Source>(), 0))
+ : decltype(__is_path_src(std::declval<const _Source&>(), 0))
{ };
template<typename _Tp1, typename _Tp2 = void>
diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h
index c5fc3beed1f..0a8f4eee0a1 100644
--- a/libstdc++-v3/include/experimental/bits/fs_path.h
+++ b/libstdc++-v3/include/experimental/bits/fs_path.h
@@ -124,7 +124,7 @@ namespace __detail
template<typename _Source>
struct __constructible_from<_Source, void>
- : decltype(__is_path_src(std::declval<_Source>(), 0))
+ : decltype(__is_path_src(std::declval<const _Source&>(), 0))
{ };
template<typename _Tp1, typename _Tp2 = void,
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc
new file mode 100644
index 00000000000..eb8473e600e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc
@@ -0,0 +1,14 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <filesystem>
+
+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 <experimental/filesystem>
+
+void f(bool) { }
+void f(const std::experimental::filesystem::path&) { }
+
+void
+test_100630()
+{
+ volatile bool b = true;
+ f(b);
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630]
2021-05-17 14:02 [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630] Jonathan Wakely
@ 2021-05-17 14:25 ` Jonathan Wakely
2021-05-17 17:14 ` Jonathan Wakely
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2021-05-17 14:25 UTC (permalink / raw)
To: libstdc++, gcc-patches
On 17/05/21 15:02 +0100, Jonathan Wakely wrote:
>The constraint check for filesystem::path construction uses
>decltype(__is_path_src(declval<Source>())) 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<const Source&>(),
>not declval<Source>(). 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.
>
>Tested x86_64-linux, pushed to gcc-10 (this isn't needed for gcc-11 or
>trunk, but I also plan to backport it to gcc-9).
Oh actually this is needed for experimental::filesystem::path on trun
kand gcc-11 (as I found when I added to the new tests to trunk) so
I'll fix it there too.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630]
2021-05-17 14:25 ` Jonathan Wakely
@ 2021-05-17 17:14 ` Jonathan Wakely
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2021-05-17 17:14 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1416 bytes --]
On 17/05/21 15:25 +0100, Jonathan Wakely wrote:
>On 17/05/21 15:02 +0100, Jonathan Wakely wrote:
>>The constraint check for filesystem::path construction uses
>>decltype(__is_path_src(declval<Source>())) 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<const Source&>(),
>>not declval<Source>(). 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.
>>
>>Tested x86_64-linux, pushed to gcc-10 (this isn't needed for gcc-11 or
>>trunk, but I also plan to backport it to gcc-9).
>
>Oh actually this is needed for experimental::filesystem::path on trun
>kand gcc-11 (as I found when I added to the new tests to trunk) so
>I'll fix it there too.
Here's the patch for trunk and gcc-11.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2868 bytes --]
commit 45aa7a447652e8541cc381d7ab128544f81ed857
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon May 17 11:54:06 2021
libstdc++: Fix filesystem::path constraints for volatile [PR 100630]
The constraint check for filesystem::path construction uses
decltype(__is_path_src(declval<Source>())) 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<const Source&>(),
not declval<Source>(). This avoids the problem of volatile-qualified
rvalues, because we no longer use an rvalue at all.
libstdc++-v3/ChangeLog:
PR libstdc++/100630
* include/experimental/bits/fs_path.h (__is_constructible_from):
Test construction from a const lvalue, not an rvalue.
* testsuite/27_io/filesystem/path/construct/100630.cc: New test.
* testsuite/experimental/filesystem/path/construct/100630.cc:
New test.
diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h
index 2df2bba3dcd..1ecf2f3a7bd 100644
--- a/libstdc++-v3/include/experimental/bits/fs_path.h
+++ b/libstdc++-v3/include/experimental/bits/fs_path.h
@@ -124,7 +124,7 @@ namespace __detail
template<typename _Source>
struct __constructible_from<_Source, void>
- : decltype(__is_path_src(std::declval<_Source>(), 0))
+ : decltype(__is_path_src(std::declval<const _Source&>(), 0))
{ };
template<typename _Tp1, typename _Tp2 = void,
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc
new file mode 100644
index 00000000000..eb8473e600e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/100630.cc
@@ -0,0 +1,14 @@
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <filesystem>
+
+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 <experimental/filesystem>
+
+void f(bool) { }
+void f(const std::experimental::filesystem::path&) { }
+
+void
+test_100630()
+{
+ volatile bool b = true;
+ f(b);
+}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-05-17 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 14:02 [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630] Jonathan Wakely
2021-05-17 14:25 ` Jonathan Wakely
2021-05-17 17:14 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).