[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-21 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #12 from CVS Commits  ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
:

https://gcc.gnu.org/g:566ba72126288272607374a32ac646dcd36fe584

commit r10-8163-g566ba72126288272607374a32ac646dcd36fe584
Author: Jonathan Wakely 
Date:   Thu May 21 07:47:17 2020 +0100

libstdc++: Avoid constraint recursion with iterator_traits (PR 93983)

Checking whether a filesystem::path constructor argument is an iterator
requires instantiating std::iterator_traits. In C++20 that checks for
satisfaction of std::iterator_traits constraints, which checks if the
type is copyable, which can end up recursing back to the path
constructor. The fix in LWG 3420 is to reorder the cpp17-iterator
concept's constraints to check if the type looks vaguely like an
iterator before checking copyable. That avoids the recursion for types
which definitely aren't iterators, but isn't foolproof.

Backport from mainline
2020-05-21  Jonathan Wakely  

PR libstdc++/93983
* include/bits/iterator_concepts.h (__detail::__cpp17_iterator):
Reorder constraints to avoid recursion when constructors use
iterator_traits (LWG 3420).
* testsuite/24_iterators/customization_points/lwg3420.cc: New test.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Jonathan Wakely  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED
   Target Milestone|--- |10.2

--- Comment #13 from Jonathan Wakely  ---
Fixed for 10.2

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-21 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #11 from CVS Commits  ---
The master branch has been updated by Jonathan Wakely :

https://gcc.gnu.org/g:f094665d465cdf8903797cc58bea13007e588616

commit r11-541-gf094665d465cdf8903797cc58bea13007e588616
Author: Jonathan Wakely 
Date:   Thu May 21 07:32:15 2020 +0100

libstdc++: Avoid constraint recursion with iterator_traits (PR 93983)

Checking whether a filesystem::path constructor argument is an iterator
requires instantiating std::iterator_traits. In C++20 that checks for
satisfaction of std::iterator_traits constraints, which checks if the
type is copyable, which can end up recursing back to the path
constructor. The fix in LWG 3420 is to reorder the cpp17-iterator
concept's constraints to check if the type looks vaguely like an
iterator before checking copyable. That avoids the recursion for types
which definitely aren't iterators, but isn't foolproof.

PR libstdc++/93983
* include/bits/iterator_concepts.h (__detail::__cpp17_iterator):
Reorder constraints to avoid recursion when constructors use
iterator_traits (LWG 3420).
* testsuite/24_iterators/customization_points/lwg3420.cc: New test.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Jonathan Wakely  changed:

   What|Removed |Added

 CC||s_gccbugzilla at nedprod dot 
com

--- Comment #10 from Jonathan Wakely  ---
*** Bug 95233 has been marked as a duplicate of this bug. ***

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #9 from Jonathan Wakely  ---
Thanks, Tim. I'd forgotten about that issue and was about to reinvent the
resolution.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-20 Thread rs2740 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #8 from TC  ---
(really from Tim)

This is https://cplusplus.github.io/LWG/issue3420

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #7 from Jonathan Wakely  ---
(In reply to Lyberta from comment #0)
> #include 
> #include 
> 
> struct Foo
> {
> Foo(const std::filesystem::path& p);
> };
> 
> static_assert(std::copyable);

The problem is that copyable considers the Foo(const path&) constructor to
see if it can be called with a const Foo&. That considers this constructor with
Foo substituted for Source:

filesystem::path(Source const&, format = auto_format);

The constraints for Source involve checking whether Source is a
Cpp17InputIterator, which is done with this:

  template>
using __is_path_iter_src
  = __and_<__is_encoded_char,
   std::is_base_of>;

So we instantiate iterator_traits.

In C++20 finding the matching specialization for std::iterator_traits
checks for concept satisfaction, which includes checking copyable which is
recursive.

An even smaller reproducer is:

#include 

struct X
{
  template::iterator_category>
X(const T&);
};

static_assert( std::copyable );

I can fix filesystem::path to avoid using iterator_traits, but this seems like
it's going to cause problems for plenty of other code too.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||rejects-valid
 Status|UNCONFIRMED |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |redi at gcc dot gnu.org
 Ever confirmed|0   |1
   Last reconfirmed||2020-05-12

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-05-12 Thread gcc-bugs at marehr dot dialup.fu-berlin.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

gcc-bugs at marehr dot dialup.fu-berlin.de changed:

   What|Removed |Added

 CC||gcc-bugs at marehr dot 
dialup.fu-b
   ||erlin.de

--- Comment #6 from gcc-bugs at marehr dot dialup.fu-berlin.de ---
It seems that I hit the same issue when making us of ranges:

```c++
#include 
#include 

static_assert(std::input_iterator);

struct alignment_file_input
{
  alignment_file_input(std::filesystem::path);

  template 
  alignment_file_input(stream_t);

  int* begin();
  int* end();
};
static_assert(std::ranges::input_range);

int main()
{
  alignment_file_input fin{int{}};

  auto && view = fin | std::views::take(1);
}
```

https://godbolt.org/z/__hw9w

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-03-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #5 from Jonathan Wakely  ---
(In reply to Paco Arjonilla from comment #4)
> There is no reason why an extra constructor would affect the semiregularity
> of a type.

That's not true.

A private or deleted constructor that is a better match for some arguments can
affect it.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-03-21 Thread pacoarjonilla at yahoo dot es
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Paco Arjonilla  changed:

   What|Removed |Added

 CC||pacoarjonilla at yahoo dot es

--- Comment #4 from Paco Arjonilla  ---
I got this error too. This is the code:



#include 
#include 
struct A {
A() = default;
A(A const&) = default;
A & operator = (A const&) = default;

A(std::filesystem::path); // This line triggers the error.
};
static_assert(std::semiregular);



There is no reason why an extra constructor would affect the semiregularity of
a type.



$> g++ -std=c++20

In file included from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/compare:39,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/stl_pair.h:65,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/stl_algobase.h:64,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/char_traits.h:39,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/string:40,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/stdexcept:39,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/system_error:41,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_fwd.h:35,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/filesystem:44,

 from :1:

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/stl_iterator_base_types.h:
In instantiation of 'struct std::iterator_traits':

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_path.h:84:11:
  required by substitution of 'template using
__is_path_iter_src = std::__and_::type, char>,
std::is_same::type, char8_t>, std::is_same::type, wchar_t>,
std::is_same::type, char16_t>, std::is_same::type, char32_t> >,
std::is_base_of > [with _Iter = A; _Iter_traits =
std::iterator_traits]'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_path.h:91:5:
  required by substitution of 'template
std::filesystem::__cxx11::__detail::__is_path_iter_src<_Iter>
std::filesystem::__cxx11::__detail::__is_path_src(_Iter, int) [with _Iter = A]'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_path.h:115:29:
  required from 'struct
std::filesystem::__cxx11::__detail::__constructible_from'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/type_traits:138:12:
  required from 'struct std::__and_ >,
std::filesystem::__cxx11::__detail::__constructible_from >'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/type_traits:143:12:
  required from 'struct std::__and_ >, std::__not_ >,
std::filesystem::__cxx11::__detail::__constructible_from >'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_path.h:119:11:
  required by substitution of 'template using _Path =
typename std::enable_if >::type,
std::filesystem::__cxx11::path> >, std::__not_::type> >,
std::filesystem::__cxx11::__detail::__constructible_from<_Tp1, _Tp2> >::value,
std::filesystem::__cxx11::path>::type [with _Tp1 = A; _Tp2 = void]'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/fs_path.h:219:7:
  required by substitution of 'template
std::filesystem::__cxx11::path::path(const _Source&,
std::filesystem::__cxx11::path::format) [with _Source = A; _Require =
]'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/type_traits:901:30:
  required from 'struct std::__is_constructible_impl'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/type_traits:906:12:
  required from 'struct std::is_constructible'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/type_traits:3091:25:
  required from 'constexpr const bool std::is_constructible_v'

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/concepts:139:30:  
required from here

/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/concepts:139:30:
error: the value of 'std::is_constructible_v' is not usable in a constant
expression

  139 |   = destructible<_Tp> && is_constructible_v<_Tp, _Args...>;

  |  ^

In file included from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/move.h:57,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/bits/nested_exception.h:40,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/exception:148,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/stdexcept:38,

 from
/opt/compiler-explorer/gcc-trunk-20200321/include/c++/10.0.1/system_error:41,

 from

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-03-01 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Jonathan Wakely  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=93923

--- Comment #3 from Jonathan Wakely  ---
This is nothing to do with concepts:

#include 

struct path {
template ::value_type,
char>>
>
path(Source const&);
};

struct Bar
{
Bar(const path& p);
};

#ifdef ADD_THIS
static_assert(!std::is_constructible_v);
#endif
static_assert(std::is_copy_constructible_v);


See also PR 93923.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-02-29 Thread barry.revzin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

--- Comment #2 from Barry Revzin  ---
(From Tim) This is LWG 3244.

[Bug libstdc++/93983] std::filesystem::path is not concept-friendly

2020-02-29 Thread barry.revzin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93983

Barry Revzin  changed:

   What|Removed |Added

 CC||barry.revzin at gmail dot com

--- Comment #1 from Barry Revzin  ---
Here's a shorter reproduction without filesystem:

#include 
#include 

struct path {
template ::value_type,
char>>
>
path(Source const&);
};

struct Bar
{
Bar(const path& p);
};

#ifdef ADD_THIS
static_assert(!std::constructible_from);
#endif
static_assert(std::copyable);

If ADD_THIS isn't defined, the copyable check is a hard error. If it is
defined, compiles fine.

https://godbolt.org/z/FEoiwA