Currently the <filesystem> header is installed unconditionally, even if the libstdc++fs.a library is not installed. Either the headers should not be installed, or the feature test macro should not be defined.
Same for <experimental/filesystem> and __cpp_lib_experimental_filesystem.
Thinking further about this, I think <filesystem> should always be installed, but it should only define the portable parts. The enumeration types, filesystem::path, filesystem::filesystem_error and filesystem::directory_entry are all supportable for any hosted implementation. Directory iterators and filesystem operations require OS support, so should be conditionally-supported. The C++17 implementation needs to move from libstdc++fs.a into libstdc++.so anyway, so that simplifies things a little. (In reply to Jonathan Wakely from comment #1) > Same for <experimental/filesystem> and __cpp_lib_experimental_filesystem. It looks like that is already dependent on ENABLE_FILESYSTEM_TS so nothing to do there.
Author: redi Date: Sun Jan 6 22:34:29 2019 New Revision: 267615 URL: https://gcc.gnu.org/viewcvs?rev=267615&root=gcc&view=rev Log: PR libstdc++/86756 add std::filesystem::path to libstdc++.so Move the C++17 std::filesystem::path definitions from the libstdc++fs.a archive to the main libstdc++ library. The path classes do not depend on any OS functions, so can be defined unconditionally on all targets (rather than depending on --enable-libstdcxx-filesystem-ts). The tests should pass on all targets too. PR libstdc++/86756 * config/abi/pre/gnu.ver (GLIBCXX_3.4): Make various patterns for typeinfo and vtables less greedy. (GLIBCXX_3.4.26): Export symbols for std::filesystem::path. * src/c++17/Makefile.am: Add fs_path.cc and cow-fs_path.cc. * src/c++17/Makefile.in: Regenerate. * src/c++17/cow-fs_path.cc: Move src/filesystem/cow-std-path.cc to here, and change name of included file. * src/c++17/fs_path.cc: Move src/filesystem/std-path.cc to here. * src/filesystem/Makefile.am: Remove std-path.cc and cow-std-path.cc from sources. * src/filesystem/Makefile.in: Regenerate. * src/filesystem/cow-std-path.cc: Move to src/c++17/cow-fs_path.cc. * src/filesystem/std-path.cc: Move to src/c++17/fs_path.cc. * testsuite/27_io/filesystem/path/append/path.cc: Remove -lstdc++fs from dg-options and remove dg-require-filesystem-ts. * testsuite/27_io/filesystem/path/append/source.cc: Likewise. * testsuite/27_io/filesystem/path/assign/assign.cc: Likewise. * testsuite/27_io/filesystem/path/assign/copy.cc: Likewise. * testsuite/27_io/filesystem/path/compare/compare.cc: Likewise. * testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise. * testsuite/27_io/filesystem/path/compare/path.cc: Likewise. * testsuite/27_io/filesystem/path/compare/strings.cc: Likewise. * testsuite/27_io/filesystem/path/concat/path.cc: Likewise. * testsuite/27_io/filesystem/path/concat/strings.cc: Likewise. * testsuite/27_io/filesystem/path/construct/80762.cc: Likewise. * testsuite/27_io/filesystem/path/construct/copy.cc: Likewise. * testsuite/27_io/filesystem/path/construct/default.cc: Likewise. * testsuite/27_io/filesystem/path/construct/format.cc: Likewise. * testsuite/27_io/filesystem/path/construct/locale.cc: Likewise. * testsuite/27_io/filesystem/path/construct/range.cc: Likewise. * testsuite/27_io/filesystem/path/construct/string_view.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/extension.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/filename.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/parent_path.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/relative_path.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/root_directory.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/root_name.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/root_path.cc: Likewise. * testsuite/27_io/filesystem/path/decompose/stem.cc: Likewise. * testsuite/27_io/filesystem/path/generation/normal.cc: Likewise. * testsuite/27_io/filesystem/path/generation/normal2.cc: Likewise. * testsuite/27_io/filesystem/path/generation/proximate.cc: Likewise. * testsuite/27_io/filesystem/path/generation/relative.cc: Likewise. * testsuite/27_io/filesystem/path/generic/generic_string.cc: Likewise. * testsuite/27_io/filesystem/path/itr/components.cc: Likewise. * testsuite/27_io/filesystem/path/itr/traversal.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/clear.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/make_preferred.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/remove_filename.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/replace_extension.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/replace_filename.cc: Likewise. * testsuite/27_io/filesystem/path/modifiers/swap.cc: Likewise. * testsuite/27_io/filesystem/path/native/string.cc: Likewise. * testsuite/27_io/filesystem/path/nonmember/append.cc: Likewise. * testsuite/27_io/filesystem/path/nonmember/hash_value.cc: Likewise. * testsuite/27_io/filesystem/path/query/empty.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_extension.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_filename.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_parent_path.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_relative_path.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_root_directory.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_root_name.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_root_path.cc: Likewise. * testsuite/27_io/filesystem/path/query/has_stem.cc: Likewise. * testsuite/27_io/filesystem/path/query/is_absolute.cc: Likewise. * testsuite/27_io/filesystem/path/query/is_relative.cc: Likewise. Added: trunk/libstdc++-v3/src/c++17/cow-fs_path.cc - copied, changed from r267614, trunk/libstdc++-v3/src/filesystem/cow-std-path.cc trunk/libstdc++-v3/src/c++17/fs_path.cc - copied, changed from r267614, trunk/libstdc++-v3/src/filesystem/std-path.cc Removed: trunk/libstdc++-v3/src/filesystem/cow-std-path.cc trunk/libstdc++-v3/src/filesystem/std-path.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/config/abi/pre/gnu.ver trunk/libstdc++-v3/src/c++17/Makefile.am trunk/libstdc++-v3/src/c++17/Makefile.in trunk/libstdc++-v3/src/filesystem/Makefile.am trunk/libstdc++-v3/src/filesystem/Makefile.in trunk/libstdc++-v3/testsuite/27_io/filesystem/path/append/path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/assign/assign.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/compare/compare.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/compare/lwg2936.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/compare/path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/compare/strings.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/concat/strings.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/80762.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/copy.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/default.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/locale.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/range.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/construct/string_view.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/extension.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/filename.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/parent_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/relative_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_directory.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_name.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/root_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/decompose/stem.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/generation/normal2.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/generation/proximate.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/generation/relative.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/generic/generic_string.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/itr/components.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/clear.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/make_preferred.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/remove_filename.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_extension.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/replace_filename.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/modifiers/swap.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/native/string.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/append.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/nonmember/hash_value.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/empty.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_extension.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_filename.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_parent_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_relative_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_directory.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_name.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_root_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/has_stem.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_absolute.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/path/query/is_relative.cc
Author: redi Date: Sun Jan 6 22:34:37 2019 New Revision: 267616 URL: https://gcc.gnu.org/viewcvs?rev=267616&root=gcc&view=rev Log: PR libstdc++/86756 Move rest of std::filesystem to libstdc++.so Move std::filesystem directory iterators and operations from libstdc++fs.a to main libstdc++ library. These components have many dependencies on OS support, which is not available on all targets. Some additional autoconf checks and conditional compilation is needed to ensure the files will build for all targets. Previously this code was not compiled without --enable-libstdcxx-filesystem-ts but the C++17 components should be available for all hosted builds. The tests for these components no longer need to link to libstdc++fs.a, but are not expected to pass on all targets. To avoid numerous failures on targets which are not expected to pass the tests (due to missing OS functionality) leave the dg-require-filesystem-ts directives in place for now. This will ensure the tests only run for builds where the filesystem-ts library is built, which presumably means some level of OS support is present. PR libstdc++/86756 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for utime and lstat and define _GLIBCXX_USE_UTIME and _GLIBCXX_USE_LSTAT. * config.h.in: Regenerate. * config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export symbols for remaining std::filesystem types and functions. * configure: Regenerate. * src/c++17/Makefile.am: Add C++17 filesystem sources. * src/c++17/Makefile.in: Regenerate. * src/c++17/cow-fs_dir.cc: Move src/filesystem/cow-std-dir.cc to here, and change name of included file. * src/c++17/cow-fs_ops.cc: Move src/filesystem/cow-std-ops.cc to here, and change name of included file. * src/c++17/fs_dir.cc: Move src/filesystem/std-dir.cc to here. Change path to dir-common.h. * src/c++17/fs_ops.cc: Move src/filesystem/std-ops.cc to here. Change path to ops-common.h. Disable -Wunused-parameter warnings. (internal_file_clock): Define unconditionally. [!_GLIBCXX_HAVE_SYS_STAT_H] (internal_file_clock::from_stat): Do not define. (do_copy_file, do_space): Move definitions to ops.common.h. (copy, file_size, hard_link_count, last_write_time, space): Only perform operation when _GLIBCXX_HAVE_SYS_STAT_H is defined, otherwise report an error. (last_write_time, read_symlink): Remove unused attributes from parameters. * src/filesystem/Makefile.am: Remove C++17 filesystem sources. * src/filesystem/Makefile.in: Regenerate. * src/filesystem/cow-std-dir.cc: Move to src/c++17/cow-fs_dir.cc. * src/filesystem/cow-std-ops.cc: Move to src/c++17/cow-fs_ops.cc. * src/filesystem/std-dir.cc: Move to src/c++17/fs_dir.cc. * src/filesystem/std-ops.cc: Move to src/c++17/fs_ops.cc. * src/filesystem/dir-common.h [!_GLIBCXX_HAVE_DIRENT_H]: Define dummy types and functions instead of using #error. * src/filesystem/dir.cc [!_GLIBCXX_HAVE_DIRENT_H]: Use #error. * src/filesystem/ops-common.h [!_GLIBCXX_USE_LSTAT] (lstat): Define in terms of stat. [!_GLIBCXX_HAVE_UNISTD_H]: Define dummy types and functions. (do_copy_file, do_space): Move definitions here from std-ops.cc. * src/filesystem/ops.cc: Adjust calls to do_copy_file and do_space to account for new namespace. * testsuite/27_io/filesystem/directory_entry/86597.cc: Remove -lstdc++fs from dg-options. * testsuite/27_io/filesystem/directory_entry/lwg3171.cc: Likewise. * testsuite/27_io/filesystem/file_status/1.cc: Likewise. * testsuite/27_io/filesystem/filesystem_error/cons.cc: Likewise. * testsuite/27_io/filesystem/filesystem_error/copy.cc: Likewise. * testsuite/27_io/filesystem/iterators/directory_iterator.cc: Likewise. * testsuite/27_io/filesystem/iterators/pop.cc: Likewise. * testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc: Likewise. * testsuite/27_io/filesystem/operations/absolute.cc: Likewise. * testsuite/27_io/filesystem/operations/canonical.cc: Likewise. * testsuite/27_io/filesystem/operations/copy.cc: Likewise. * testsuite/27_io/filesystem/operations/copy_file.cc: Likewise. * testsuite/27_io/filesystem/operations/create_directories.cc: Likewise. * testsuite/27_io/filesystem/operations/create_directory.cc: Likewise. * testsuite/27_io/filesystem/operations/create_symlink.cc: Likewise. * testsuite/27_io/filesystem/operations/current_path.cc: Likewise. * testsuite/27_io/filesystem/operations/equivalent.cc: Likewise. * testsuite/27_io/filesystem/operations/exists.cc: Likewise. * testsuite/27_io/filesystem/operations/file_size.cc: Likewise. * testsuite/27_io/filesystem/operations/is_empty.cc: Likewise. * testsuite/27_io/filesystem/operations/last_write_time.cc: Likewise. * testsuite/27_io/filesystem/operations/permissions.cc: Likewise. * testsuite/27_io/filesystem/operations/proximate.cc: Likewise. * testsuite/27_io/filesystem/operations/read_symlink.cc: Likewise. * testsuite/27_io/filesystem/operations/relative.cc: Likewise. * testsuite/27_io/filesystem/operations/remove.cc: Likewise. * testsuite/27_io/filesystem/operations/remove_all.cc: Likewise. * testsuite/27_io/filesystem/operations/space.cc: Likewise. * testsuite/27_io/filesystem/operations/status.cc: Likewise. * testsuite/27_io/filesystem/operations/symlink_status.cc: Likewise. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: Likewise. * testsuite/27_io/filesystem/operations/weakly_canonical.cc: Likewise. Added: trunk/libstdc++-v3/src/c++17/cow-fs_dir.cc - copied, changed from r267615, trunk/libstdc++-v3/src/filesystem/cow-std-dir.cc trunk/libstdc++-v3/src/c++17/cow-fs_ops.cc - copied, changed from r267615, trunk/libstdc++-v3/src/filesystem/cow-std-ops.cc trunk/libstdc++-v3/src/c++17/fs_dir.cc - copied, changed from r267615, trunk/libstdc++-v3/src/filesystem/std-dir.cc trunk/libstdc++-v3/src/c++17/fs_ops.cc - copied, changed from r267615, trunk/libstdc++-v3/src/filesystem/std-ops.cc Removed: trunk/libstdc++-v3/src/filesystem/cow-std-dir.cc trunk/libstdc++-v3/src/filesystem/cow-std-ops.cc trunk/libstdc++-v3/src/filesystem/std-dir.cc trunk/libstdc++-v3/src/filesystem/std-ops.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/acinclude.m4 trunk/libstdc++-v3/config.h.in trunk/libstdc++-v3/config/abi/pre/gnu.ver trunk/libstdc++-v3/configure trunk/libstdc++-v3/src/c++17/Makefile.am trunk/libstdc++-v3/src/c++17/Makefile.in trunk/libstdc++-v3/src/filesystem/Makefile.am trunk/libstdc++-v3/src/filesystem/Makefile.in trunk/libstdc++-v3/src/filesystem/dir-common.h trunk/libstdc++-v3/src/filesystem/dir.cc trunk/libstdc++-v3/src/filesystem/ops-common.h trunk/libstdc++-v3/src/filesystem/ops.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/directory_entry/86597.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/directory_entry/lwg3171.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/file_status/1.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/filesystem_error/cons.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/filesystem_error/copy.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/iterators/directory_iterator.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/iterators/pop.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/canonical.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/copy.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/copy_file.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directories.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/create_directory.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/create_symlink.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/current_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/equivalent.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/exists.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/file_size.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/is_empty.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/last_write_time.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/permissions.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/proximate.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/read_symlink.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/relative.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/remove.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/remove_all.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/space.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/status.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/symlink_status.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/temp_directory_path.cc trunk/libstdc++-v3/testsuite/27_io/filesystem/operations/weakly_canonical.cc
The C++17 std::filesystem library is now supported unconditionally, so it's correct to define __cpp_lib_filesystem unconditionally. So this is fixed.
The patch for this issue seems to have caused several test regressions and new failures on nios2-elf, a newlib-based target with semihosted i/o. It's getting link-time errors about references to undefined symbols chdir, mkdir, etc. It's not clear how I'm supposed to fix that. Am I missing some configure option, or should I be adding dg-skip-if (or whatever) to the failing tests?
There are more changes needed to the library code, to stop using chdir, mkdir etc. when not supported. This was first brought up in https://gcc.gnu.org/ml/libstdc++/2019-01/msg00039.html I'm not sure how to detect whether those functions are usable though, because apparently they're declared during compilation but absent when loading libstdc++.so at runtime.