Topic: possible LWG defect : filesystem::path::has_parent_path()


Author: akirat@preferred.jp
Date: Wed, 10 Jan 2018 20:31:32 -0800 (PST)
Raw View
------=_Part_4073_1874477629.1515645092452
Content-Type: multipart/alternative;
 boundary="----=_Part_4074_1397755892.1515645092453"

------=_Part_4074_1397755892.1515645092453
Content-Type: text/plain; charset="UTF-8"

Hi,
Follow specification is right or bug? If bug, I'll report to LWG.

#include <iostream>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path p = "/"; // POSIX system (or "C:/" on Windows)

  // actual output is "true". right?
  // expected output is "false". because root path doesn't have parent.
  std::cout << std::boolalpha << p.has_parent_path() << std::endl;
}

Spec:
30.11.7.4.10 path query [fs.path.query]
bool has_parent_path() const;
Returns: !parent_path().empty().

I think the spec should be:
Returns: has_relative_path() && !parent_path().empty().

As additional information, parent_path() function changed by US 58 NB
Comment.
>  *this if !has_relative_path(), ...
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0488r0.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0492r2.html

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/60488025-fcf8-499a-b82d-ae76341c6acd%40isocpp.org.

------=_Part_4074_1397755892.1515645092453
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<div>Follow specification is right or bug? If bug, I&#3=
9;ll report to LWG.</div><div><br></div><div><div>#include &lt;iostream&gt;=
</div><div>#include &lt;filesystem&gt;</div><div><br></div><div>namespace f=
s =3D std::filesystem;</div><div><br></div><div>int main()</div><div>{</div=
><div>=C2=A0 fs::path p =3D &quot;/&quot;; // POSIX system (or &quot;C:/&qu=
ot; on Windows)</div><div><br></div><div>=C2=A0 // actual output is &quot;t=
rue&quot;. right?</div><div>=C2=A0 // expected output is &quot;false&quot;.=
 because root path doesn&#39;t have parent.</div><div>=C2=A0 std::cout &lt;=
&lt; std::boolalpha &lt;&lt; p.has_parent_path() &lt;&lt; std::endl;</div><=
div>}</div></div><div><br></div><div>Spec:</div><div><div>30.11.7.4.10 path=
 query [fs.path.query]</div><div><div>bool has_parent_path() const;</div><d=
iv>Returns: !parent_path().empty().</div></div></div><div><br></div><div>I =
think the spec should be:</div><div>Returns: has_relative_path() &amp;&amp;=
 !parent_path().empty().</div><div><br></div><div>As additional information=
, parent_path() function changed by US 58 NB Comment.</div><div>&gt;=C2=A0=
=C2=A0*this if !has_relative_path(), ...</div><div>http://www.open-std.org/=
jtc1/sc22/wg21/docs/papers/2016/p0488r0.pdf<br></div><div>http://www.open-s=
td.org/jtc1/sc22/wg21/docs/papers/2017/p0492r2.html<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/60488025-fcf8-499a-b82d-ae76341c6acd%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/60488025-fcf8-499a-b82d-ae76341c6acd=
%40isocpp.org</a>.<br />

------=_Part_4074_1397755892.1515645092453--

------=_Part_4073_1874477629.1515645092452--

.


Author: Edward Catmur <ed@catmur.co.uk>
Date: Thu, 11 Jan 2018 16:01:10 -0800 (PST)
Raw View
------=_Part_812_2135292812.1515715270580
Content-Type: multipart/alternative;
 boundary="----=_Part_813_1354156417.1515715270580"

------=_Part_813_1354156417.1515715270580
Content-Type: text/plain; charset="UTF-8"



On Thursday, 11 January 2018 04:31:32 UTC, aki...@preferred.jp wrote:
>
> Hi,
> Follow specification is right or bug? If bug, I'll report to LWG.
>
> #include <iostream>
> #include <filesystem>
>
> namespace fs = std::filesystem;
>
> int main()
> {
>   fs::path p = "/"; // POSIX system (or "C:/" on Windows)
>
>   // actual output is "true". right?
>   // expected output is "false". because root path doesn't have parent.
>   std::cout << std::boolalpha << p.has_parent_path() << std::endl;
> }
>
> Spec:
> 30.11.7.4.10 path query [fs.path.query]
> bool has_parent_path() const;
> Returns: !parent_path().empty().
>
> I think the spec should be:
> Returns: has_relative_path() && !parent_path().empty().
>

Currently each has_XXX() query is precisely equivalent to !XXX().empty().
It would be inconsistent for has_parent_path() to behave differently.

If has_parent_path() were to return false on root paths, it would be
necessary for parent_path() to return empty on root paths. This would be
confusing, since on most Unix-like operating systems "/.." is "/", and on
Windows "C:\\.." is "C:\\".

POSIX defines "parent directory" as:
> When discussing a given directory, the directory that both contains a
directory entry for the given directory and is represented by the pathname
dot-dot in the given directory.

For the root directory, given that both /. and /.. refer to /, the root is
its own parent. I think this is on balance the least surprising option.

As additional information, parent_path() function changed by US 58 NB
> Comment.
> >  *this if !has_relative_path(), ...
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0488r0.pdf
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0492r2.html
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d1f4547b-0d84-4fbe-b607-043264366fb4%40isocpp.org.

------=_Part_813_1354156417.1515715270580
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Thursday, 11 January 2018 04:31:32 UTC, aki...@=
preferred.jp  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">Hi,<div>Follow specification is right or bug? If bug, I&#39;ll rep=
ort to LWG.</div><div><br></div><div><div>#include &lt;iostream&gt;</div><d=
iv>#include &lt;filesystem&gt;</div><div><br></div><div>namespace fs =3D st=
d::filesystem;</div><div><br></div><div>int main()</div><div>{</div><div>=
=C2=A0 fs::path p =3D &quot;/&quot;; // POSIX system (or &quot;C:/&quot; on=
 Windows)</div><div><br></div><div>=C2=A0 // actual output is &quot;true&qu=
ot;. right?</div><div>=C2=A0 // expected output is &quot;false&quot;. becau=
se root path doesn&#39;t have parent.</div><div>=C2=A0 std::cout &lt;&lt; s=
td::boolalpha &lt;&lt; p.has_parent_path() &lt;&lt; std::endl;</div><div>}<=
/div></div><div><br></div><div>Spec:</div><div><div>30.11.7.4.10 path query=
 [fs.path.query]</div><div><div>bool has_parent_path() const;</div><div>Ret=
urns: !parent_path().empty().</div></div></div><div><br></div><div>I think =
the spec should be:</div><div>Returns: has_relative_path() &amp;&amp; !pare=
nt_path().empty().</div></div></blockquote><div><br></div><div>Currently ea=
ch has_XXX() query is precisely equivalent to !XXX().empty(). It would be i=
nconsistent for has_parent_path() to behave differently.</div><div><br></di=
v><div>If has_parent_path() were to return false on root paths, it would be=
 necessary for parent_path() to return empty on root paths. This would be c=
onfusing, since on most Unix-like operating systems &quot;/..&quot; is &quo=
t;/&quot;, and on Windows &quot;C:\\..&quot; is &quot;C:\\&quot;.</div><div=
><br></div><div>POSIX defines &quot;parent directory&quot; as:</div><div>&g=
t;=C2=A0<span style=3D"color: rgb(0, 0, 0); font-family: Verdana, Arial, He=
lvetica, sans-serif; font-size: 13.3333px;">When discussing a given directo=
ry, the directory that both contains a directory entry for the given direct=
ory and is represented by the pathname dot-dot in the given directory.</spa=
n></div><div><span style=3D"color: rgb(0, 0, 0); font-family: Verdana, Aria=
l, Helvetica, sans-serif; font-size: 13.3333px;"><br></span></div><div>For =
the root directory, given that both /. and /.. refer to /, the root is its =
own parent. I think this is on balance the least surprising option.</div><d=
iv><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
<div></div><div>As additional information, parent_path() function changed b=
y US 58 NB Comment.</div><div>&gt;=C2=A0=C2=A0*this if !has_relative_path()=
, ...</div><div><a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/pape=
rs/2016/p0488r0.pdf" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this=
..href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2=
Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0488r0.pdf\x26sa\x3dD\x26sntz=
\x3d1\x26usg\x3dAFQjCNEwBS8wPLQ-R20XLGNjkZ_x0MZN3Q&#39;;return true;" oncli=
ck=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open=
-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0488r0.pdf\x26sa\x3=
dD\x26sntz\x3d1\x26usg\x3dAFQjCNEwBS8wPLQ-R20XLGNjkZ_x0MZN3Q&#39;;return tr=
ue;">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2016/<wbr>p048=
8r0.pdf</a><br></div><div><a href=3D"http://www.open-std.org/jtc1/sc22/wg21=
/docs/papers/2017/p0492r2.html" target=3D"_blank" rel=3D"nofollow" onmoused=
own=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.ope=
n-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2017%2Fp0492r2.html\x26sa\=
x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrF59EYYDwNuqfxsRldM8nLiLrGQ&#39;;return =
true;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2=
F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2017%2Fp0492r2.=
html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGrF59EYYDwNuqfxsRldM8nLiLrGQ&#=
39;;return true;">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2=
017/<wbr>p0492r2.html</a><br></div></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d1f4547b-0d84-4fbe-b607-043264366fb4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d1f4547b-0d84-4fbe-b607-043264366fb4=
%40isocpp.org</a>.<br />

------=_Part_813_1354156417.1515715270580--

------=_Part_812_2135292812.1515715270580--

.


Author: Jakob Riedle <jakob.riedle@gmail.com>
Date: Thu, 11 Jan 2018 23:38:12 -0800 (PST)
Raw View
------=_Part_1363_1744104863.1515742692979
Content-Type: multipart/alternative;
 boundary="----=_Part_1364_1450789921.1515742692979"

------=_Part_1364_1450789921.1515742692979
Content-Type: text/plain; charset="UTF-8"

See: http://en.cppreference.com/w/cpp/experimental/fs/path/parent_path
parent_path() does return an empty path for root, so has_parent_path()
should return false on the root path?!

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2f82daec-b46e-4071-988d-a2917bc4621b%40isocpp.org.

------=_Part_1364_1450789921.1515742692979
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">See:=C2=A0<a href=3D"http://en.cppreference.com/w/cpp/expe=
rimental/fs/path/parent_path">http://en.cppreference.com/w/cpp/experimental=
/fs/path/parent_path</a><div>parent_path() does return an empty path for ro=
ot, so has_parent_path() should return false on the root path?!</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2f82daec-b46e-4071-988d-a2917bc4621b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2f82daec-b46e-4071-988d-a2917bc4621b=
%40isocpp.org</a>.<br />

------=_Part_1364_1450789921.1515742692979--

------=_Part_1363_1744104863.1515742692979--

.


Author: Edward Catmur <ed@catmur.co.uk>
Date: Fri, 12 Jan 2018 07:46:34 -0800 (PST)
Raw View
------=_Part_2251_1952425612.1515771994542
Content-Type: multipart/alternative;
 boundary="----=_Part_2252_1129656474.1515771994543"

------=_Part_2252_1129656474.1515771994543
Content-Type: text/plain; charset="UTF-8"



On Friday, 12 January 2018 07:38:13 UTC, Jakob Riedle wrote:
>
> See: http://en.cppreference.com/w/cpp/experimental/fs/path/parent_path
> parent_path() does return an empty path for root, so has_parent_path()
> should return false on the root path?!
>

That's the TS (pre-adoption); the Standard incorporates the TS amended by
P0492R2. Note that the documentation on cppreference for the Standard
filesystem library also does not incorporate P0492R2. The draft at eel.is
(http://eel.is/c++draft/fs.path.decompose#5) appears to be up to date.

For example, the Windows root path "C:\\" decomposes as "C:" (root name),
"\\" (root directory), "" (relative path), so its parent path is "C:\\".
The Unix root path "/" decomposes as "" (root name), "/" (root directory),
"" (relative path), so its parent path is "/".

Some more examples:

"/var/tmp" -> "/var"
"here/to/there" -> "here/to"
"README.md" -> ""
"C:\\Dos\\Run" -> "C:\\Dos"
"E:Secret\\Folder" -> "X:Secret"
"X:Numbers.txt" -> "X:"

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/de6435e8-6dfe-4035-985f-5ed51236bcf5%40isocpp.org.

------=_Part_2252_1129656474.1515771994543
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, 12 January 2018 07:38:13 UTC, Jakob Rie=
dle  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Se=
e:=C2=A0<a href=3D"http://en.cppreference.com/w/cpp/experimental/fs/path/pa=
rent_path" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#=
39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2Fw%2Fcp=
p%2Fexperimental%2Ffs%2Fpath%2Fparent_path\x26sa\x3dD\x26sntz\x3d1\x26usg\x=
3dAFQjCNEBeCf-OqH1z62h3d_U3Ucmkl0R0Q&#39;;return true;" onclick=3D"this.hre=
f=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fen.cppreference.com%2F=
w%2Fcpp%2Fexperimental%2Ffs%2Fpath%2Fparent_path\x26sa\x3dD\x26sntz\x3d1\x2=
6usg\x3dAFQjCNEBeCf-OqH1z62h3d_U3Ucmkl0R0Q&#39;;return true;">http://en.cpp=
reference.<wbr>com/w/cpp/experimental/fs/<wbr>path/parent_path</a><div>pare=
nt_path() does return an empty path for root, so has_parent_path() should r=
eturn false on the root path?!</div></div></blockquote><div><br></div><div>=
That&#39;s the TS (pre-adoption); the Standard incorporates the TS amended =
by P0492R2. Note that the documentation on cppreference for the Standard fi=
lesystem library also does not incorporate P0492R2. The draft at eel.is (ht=
tp://eel.is/c++draft/fs.path.decompose#5) appears to be up to date.</div><d=
iv><br></div><div>For example, the Windows root path &quot;C:\\&quot; decom=
poses as &quot;C:&quot; (root name), &quot;\\&quot; (root directory), &quot=
;&quot; (relative path), so its parent path is &quot;C:\\&quot;. The Unix r=
oot path &quot;/&quot; decomposes as &quot;&quot; (root name), &quot;/&quot=
; (root directory), &quot;&quot; (relative path), so its parent path is &qu=
ot;/&quot;.</div><div><br></div><div>Some more examples:</div><div><br></di=
v><div>&quot;/var/tmp&quot; -&gt; &quot;/var&quot;</div><div>&quot;here/to/=
there&quot; -&gt; &quot;here/to&quot;</div><div>&quot;README.md&quot; -&gt;=
 &quot;&quot;</div><div>&quot;C:\\Dos\\Run&quot; -&gt; &quot;C:\\Dos&quot;<=
/div><div>&quot;E:Secret\\Folder&quot; -&gt; &quot;X:Secret&quot;</div><div=
>&quot;X:Numbers.txt&quot; -&gt; &quot;X:&quot;</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/de6435e8-6dfe-4035-985f-5ed51236bcf5%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/de6435e8-6dfe-4035-985f-5ed51236bcf5=
%40isocpp.org</a>.<br />

------=_Part_2252_1129656474.1515771994543--

------=_Part_2251_1952425612.1515771994542--

.