Summary: | Lack of `std::move()` inside `operator/` for `std::filesystem::path`. | ||
---|---|---|---|
Product: | gcc | Reporter: | LIU Hao <lh_mouse> |
Component: | libstdc++ | Assignee: | Jonathan Wakely <redi> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | webrown.cpp |
Priority: | P3 | ||
Version: | 8.1.1 | ||
Target Milestone: | 7.4 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2018-05-07 00:00:00 |
Description
LIU Hao
2018-05-06 13:43:31 UTC
It would be better to do: path __tmp(__lhs); __tmp /= __rhs; return __tmp; That allows a copy to be elided. 在 2018/5/7 20:13, redi at gcc dot gnu.org 写道:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85671
>
> Jonathan Wakely <redi at gcc dot gnu.org> changed:
>
> What |Removed |Added
> ----------------------------------------------------------------------------
> Status|UNCONFIRMED |ASSIGNED
> Last reconfirmed| |2018-05-07
> Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
> Ever confirmed|0 |1
>
> --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
> It would be better to do:
>
> path __tmp(__lhs);
> __tmp /= __rhs;
> return __tmp;
>
> That allows a copy to be elided.
>
There is no difference in implementation as long as NRVO is in effect.
Author: redi Date: Mon May 7 17:26:28 2018 New Revision: 260009 URL: https://gcc.gnu.org/viewcvs?rev=260009&root=gcc&view=rev Log: PR libstdc++/85671 allow copy elision in path concatenation By performing the /= operation on a named local variable instead of a temporary the copy made for the return value can be elided. PR libstdc++/85671 * include/bits/fs_path.h (operator/): Permit copy elision. * include/experimental/bits/fs_path.h (operator/): Likewise. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/fs_path.h trunk/libstdc++-v3/include/experimental/bits/fs_path.h (In reply to Liu Hao from comment #2) > There is no difference in implementation as long as NRVO is in effect. There is a difference. Using move(path(__lhs) /= __rhs) has one copy construction and one non-elided move construction. What I've committed to trunk has a copy construction and an elided move construction. Author: redi Date: Wed Jul 4 11:44:56 2018 New Revision: 262388 URL: https://gcc.gnu.org/viewcvs?rev=262388&root=gcc&view=rev Log: PR libstdc++/85671 allow copy elision in path concatenation By performing the /= operation on a named local variable instead of a temporary the copy made for the return value can be elided. Backport from mainline 2018-05-07 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/85671 * include/bits/fs_path.h (operator/): Permit copy elision. * include/experimental/bits/fs_path.h (operator/): Likewise. Modified: branches/gcc-8-branch/libstdc++-v3/ChangeLog branches/gcc-8-branch/libstdc++-v3/include/bits/fs_path.h branches/gcc-8-branch/libstdc++-v3/include/experimental/bits/fs_path.h Also fixed for 8.2 Author: redi Date: Wed Jul 4 13:59:06 2018 New Revision: 262404 URL: https://gcc.gnu.org/viewcvs?rev=262404&root=gcc&view=rev Log: PR libstdc++/85671 allow copy elision in path concatenation By performing the /= operation on a named local variable instead of a temporary the copy made for the return value can be elided. Backport from mainline 2018-05-07 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/85671 * include/experimental/bits/fs_path.h (operator/): Likewise. Modified: branches/gcc-7-branch/libstdc++-v3/ChangeLog branches/gcc-7-branch/libstdc++-v3/include/experimental/bits/fs_path.h And 7.4 |