aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
AgeCommit message (Collapse)AuthorFilesLines
2018-12-22[Patch, PowerPC/Darwin] Fix library export of long double symbols.Iain Sandoe2-0/+25
During 8.x, the rs6000 target-specific mangling was reorganised which uncovered a long-standing bug in Darwin’s mangling for ‘IBM’ long double. Now the symbols are correctly mangled, and we end up with a bunch of test link fails. This patch adds the necessary subset of the Linux long double exports to Darwin’s export table. 2018-12-22 Iain Sandoe <iain@sandoe.co.uk> * /config/os/bsd/darwin/ppc-extra.ver: Append long double symbols. From-SVN: r267358
2018-12-20Fix filesystem::path tests that fail on WindowsJonathan Wakely4-14/+43
* testsuite/27_io/filesystem/operations/proximate.cc: Fix test for MinGW. * testsuite/27_io/filesystem/path/append/source.cc: Likewise. * testsuite/27_io/filesystem/path/compare/lwg2936.cc: Likewise. From-SVN: r267308
2018-12-20Add missing test from previous commitJonathan Wakely2-0/+45
* testsuite/27_io/filesystem/directory_entry/lwg3171.cc: New test (missed from previous commit). From-SVN: r267297
2018-12-19Fix grammar in libstdc++ ABI history documentationJonathan Wakely2-1/+5
* doc/xml/manual/abi.xml: Add missing word. From-SVN: r267285
2018-12-18LWG 3171: restore stream insertion for filesystem::directory_entryJonathan Wakely2-0/+12
* include/bits/fs_dir.h (operator<<): Overload for directory_entry, as per LWG 3171. * testsuite/27_io/filesystem/directory_entry/lwg3171.cc: New test. From-SVN: r267238
2018-12-18Fix previous commit to move instead of copyingJonathan Wakely2-1/+4
* src/filesystem/std-dir.cc (filesystem::_Dir::advance): Move new path instead of copying. From-SVN: r267237
2018-12-18Micro-optimization to avoid creating temporary pathJonathan Wakely2-1/+6
Now that path::operator/=(basic_string_view<value_type>) works directly from the string argument, instead of constructing a temporary path from the string, it's potentially more efficient to do 'path(x) /= s' instead of 'x / s'. This changes the only relevant place in the library. * src/filesystem/std-dir.cc (filesystem::_Dir::advance): Append string to lvalue to avoid creating temporary path. From-SVN: r267236
2018-12-18LWG 2936: update path::compare logic and optimize string comparisonsJonathan Wakely6-79/+300
The resolution for LWG 2936 defines the comparison more precisely, which this patch implements. The patch also defines comparisons with strings to work without constructing a temporary path object (so avoids any memory allocations). * include/bits/fs_path.h (path::compare(const string_type&)) (path::compare(const value_type*)): Add noexcept and construct a string view to compare to instead of a path. (path::compare(basic_string_view<value_type>)): Add noexcept. Remove inline definition. * src/filesystem/std-path.cc (path::_Parser): Track last type read from input. (path::_Parser::next()): Return a final empty component when the input ends in a non-root directory separator. (path::_M_append(basic_string_view<value_type>)): Remove special cases for trailing non-root directory separator. (path::_M_concat(basic_string_view<value_type>)): Likewise. (path::compare(const path&)): Implement LWG 2936. (path::compare(basic_string_view<value_type>)): Define in terms of components returned by parser, consistent with LWG 2936. * testsuite/27_io/filesystem/path/compare/lwg2936.cc: New. * testsuite/27_io/filesystem/path/compare/path.cc: Test more cases. * testsuite/27_io/filesystem/path/compare/strings.cc: Likewise. From-SVN: r267235
2018-12-18LWG 3040: define starts_with/ends_with as proposedJonathan Wakely2-6/+12
* include/std/string_view [__cplusplus > 201703L] (basic_string_view::starts_with(basic_string_view)): Implement proposed resolution of LWG 3040 to avoid redundant length check. (basic_string_view::starts_with(_CharT)): Implement proposed resolution of LWG 3040 to check at most one character. (basic_string_view::ends_with(_CharT)): Likewise. From-SVN: r267234
2018-12-17PR libstdc++/71044 fix off-by-one errors introduced recentlyJonathan Wakely5-7/+93
The recent changes to append/concat directly from strings (without constructing paths) introduced regressions where one of the components could be omitted from the iteration sequence in the result. PR libstdc++/71044 * src/filesystem/std-path.cc (path::_M_append): Fix off-by-one error that caused a component to be lost from the iteration sequence. (path::_M_concat): Likewise. * testsuite/27_io/filesystem/path/append/source.cc: Test appending long strings. * testsuite/27_io/filesystem/path/concat/strings.cc: Test concatenating long strings. * testsuite/27_io/filesystem/path/construct/string_view.cc: Test construction from long string. From-SVN: r267222
2018-12-13Fix handling of POSIX paths containing a root-nameJonathan Wakely3-11/+91
Fix path appending and concatenating to work correctly for a leading root-name. Check a new macro, SLASHSLASH_IS_ROOT_NAME, instead of making the behaviour depend directly on __CYGWIN__. * src/filesystem/std-path.cc (SLASHSLASH_IS_ROOT_NAME): New macro to control whether interpret paths with two slashes as a root-name. (path::operator/=(const path&)) [SLASHSLASH_IS_ROOT_NAME]: Add a root-directory when appending to a root-name. (path::_M_append(basic_string_view<value_type>)) [SLASHSLASH_IS_ROOT_NAME]: Likewise. (path::operator/=(const path&)) [SLASHSLASH_IS_ROOT_NAME]: Likewise. (path::_M_concat(basic_string_view<value_type>)) [SLASHSLASH_IS_ROOT_NAME]: Likewise. (path::lexically_normal()) [SLASHSLASH_IS_ROOT_NAME]: Use += instead of /= to add a root-directory to the result. * testsuite/27_io/filesystem/path/decompose/root_directory.cc: Fix expected result for Cygwin. From-SVN: r267107
2018-12-13PR libstdc++/71044 optimize std::filesystem::path constructionJonathan Wakely6-244/+1461
This new implementation has a smaller footprint than the previous implementation, due to replacing std::vector<_Cmpt> with a custom pimpl type that only needs a single pointer. The _M_type enumeration is also combined with the pimpl type, by using a tagged pointer, reducing sizeof(path) further still. Construction and modification of paths is now done more efficiently, by splitting the input into a stack-based buffer of string_view objects instead of a dynamically-allocated vector containing strings. Once the final size is known only a single allocation is needed to reserve space for it. The append and concat operations no longer require constructing temporary path objects, nor re-parsing the entire native pathname. This results in algorithmic improvements to path construction, and working with large paths is much faster. PR libstdc++/71044 * include/bits/fs_path.h (path::path(path&&)): Add noexcept when appropriate. Move _M_cmpts instead of reparsing the native pathname. (path::operator=(const path&)): Do not define as defaulted. (path::operator/=, path::append): Call _M_append. (path::concat): Call _M_concat. (path::path(string_type, _Type): Change type of first parameter to basic_string_view<value_type>. (path::_M_append(basic_string_view<value_type>)): New member function. (path::_M_concat(basic_string_view<value_type>)): New member function. (_S_convert(value_type*, __null_terminated)): Return string view. (_S_convert(const value_type*, __null_terminated)): Return string view. (_S_convert(value_type*, value_type*)) (_S_convert(const value_type*, const value_type*)): Add overloads for pairs of pointers. (_S_convert(_InputIterator, __null_terminated)): Construct string_type explicitly, for cases where _S_convert returns a string view. (path::_S_is_dir_sep): Replace with non-member is_dir_sep. (path::_M_trim, path::_M_add_root_name, path::_M_add_root_dir) (path::_M_add_filename): Remove. (path::_M_type()): New member function to replace _M_type data member. (path::_List): Define new struct type instead of using std::vector. (path::_Cmpt::_Cmpt(string_type, _Type, size_t)): Change type of first parameter to basic_string_view<value_type>. (path::operator+=(const path&)): Do not define inline. (path::operator+=(const string_type&)): Call _M_concat. (path::operator+=(const value_type*)): Likewise. (path::operator+=(value_type)): Likewise. (path::operator+=(basic_string_view<value_type>)): Likewise. (path::operator/=(const path&)): Do not define inline. (path::_M_append(path)): Remove. * python/libstdcxx/v6/printers.py (StdPathPrinter): New printer that understands the new path::_List type. * src/filesystem/std-path.cc (is_dir_sep): New function to replace path::_S_is_dir_sep. (path::_Parser): New helper class to parse strings as paths. (path::_List::_Impl): Define container type for path components. (path::_List): Define members. (path::operator=(const path&)): Define explicitly, to provide the strong exception safety guarantee. (path::operator/=(const path&)): Implement manually by processing each component of the argument, rather than using _M_split_cmpts to parse the entire string again. (path::_M_append(string_type)): Likewise. (path::operator+=(const path&)): Likewise. (path::_M_concat(string_type)): Likewise. (path::remove_filename()): Perform trim directly instead of calling _M_trim(). (path::_M_split_cmpts()): Rewrite in terms of _Parser class. (path::_M_trim, path::_M_add_root_name, path::_M_add_root_dir) (path::_M_add_filename): Remove. * testsuite/27_io/filesystem/path/append/source.cc: Test appending a string view that aliases the path. testsuite/27_io/filesystem/path/concat/strings.cc: Test concatenating a string view that aliases the path. From-SVN: r267106
2018-12-13Fix [fs.path.gen] tests to use backslashes for mingwJonathan Wakely3-14/+43
The normalized paths contain backslashes so fix the expected values to use backslashes too. * testsuite/27_io/filesystem/path/generation/proximate.cc: Use preferred directory separators for normalized paths. * testsuite/27_io/filesystem/path/generation/relative.cc: Likewise. From-SVN: r267090
2018-12-13Fix test to work when path::native() returns wstringJonathan Wakely2-3/+6
* testsuite/27_io/filesystem/path/itr/traversal.cc: Fix test for mingw. From-SVN: r267089
2018-12-13Disable new tests for configurations with no libstdc++fs.aJonathan Wakely3-0/+8
* testsuite/27_io/filesystem/path/construct/80762.cc: Skip test if the Filesystem TS support is not configured. * testsuite/experimental/filesystem/path/construct/80762.cc: Likewise. From-SVN: r267082
2018-12-12Overload std::distance and std::advance for path::iteratorJonathan Wakely3-0/+66
Although filesystem::path::iterator is only a bidirectional iterator, the underlying sequence has random access iterators (specifically, raw pointers). This means std::distance and std::advance can be implemented more efficiently than the generic versions which apply ++ and -- repeatedly. PR libstdc++/71044 (partial) * include/bits/fs_path.h (__path_iter_distance, __path_iter_advance): New friend functions to implement std::distance and std::advance more efficiently. (distance, advance): Add overloads for path::iterator. * testsuite/27_io/filesystem/path/itr/components.cc: Test new overload. From-SVN: r267057
2018-12-12PR libstdc++/80762 avoid ambiguous __constructible_from<void, void>Jonathan Wakely5-2/+70
Ensure we don't try to instantiate __is_constructible_from<void, void>, because there are two partial specializations that are equally good matches. PR libstdc++/80762 * include/bits/fs_path.h (path::_Path): Use remove_cv_t and is_void. * include/experimental/bits/fs_path.h (path::_Path): Likewise. * testsuite/27_io/filesystem/path/construct/80762.cc: New test. * testsuite/experimental/filesystem/path/construct/80762.cc: New test. From-SVN: r267056
2018-12-12P0595R2 - is_constant_evaluatedJakub Jelinek5-0/+125
P0595R2 - is_constant_evaluated * include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED): Define if __builtin_is_constant_evaluated is available. * include/std/type_traits (std::is_constant_evaluated): New constexpr inline function. * testsuite/20_util/is_constant_evaluated/1.cc: New test. * testsuite/20_util/is_constant_evaluated/noexcept.cc: New test. From-SVN: r267045
2018-12-11documentation_hacking.xml: Update reference to epubcheck.Gerald Pfeifer2-1/+6
* doc/xml/manual/documentation_hacking.xml: Update reference to epubcheck. From-SVN: r266970
2018-12-10Make test for Filesystem TS actually use the Filesystem TSJonathan Wakely2-5/+10
This test was copied from 27_io/filesystem/path/query/is_absolute.cc but should have been modified to test the path type from the TS instead of std::filesystem::path. * testsuite/experimental/filesystem/path/query/is_absolute.cc: Fix test to use TS, not C++17. From-SVN: r266957
2018-12-06Darwin fix libstdc++ build warnings.Iain Sandoe2-0/+13
GCC does not export construction vtable symbols from shared libraries. The symbols are marked hidden in the objects; for Darwin that makes them also external (“private_extern” is Darwin’s hidden) which means that they show up in the list of possible symbols for export from libstdc++, and there are sufficiently relaxed match conditions that they reach the exports list. When Darwin’s static linker encounters them it generates a warning that they cannot be exported. This patch prunes them from the list of symbols to be considered, thus eliminating the warnings. No functional Change inended to the library exports. 2018-12-06 Iain Sandoe <iain@sandoe.co.uk> * scripts/make_exports.pl (check names): Don’t try to export construction vtable symbols. From-SVN: r266864
2018-12-06Fix PR libstdc++/64883 Darwin headers use always_inline so don't test thatJonathan Wakely6-8/+19
Because darwin system headers use always_inline rather than __always_inline__ the libstdc++ test will fail, even if our headers only use the reserved form of the attribute. Don't test it on Darwin, and assume that testing on other targets will catch any accidental misuses in libstdc++ headers. 2018-12-06 Jonathan Wakely <jwakely@redhat.com> Iain Sandoe <iain@sandoe.co.uk> PR libstdc++/64883 * testsuite/17_intro/headers/c++1998/all_attributes.cc: Don't test always_inline on Darwin. * testsuite/17_intro/headers/c++2011/all_attributes.cc: Likewise. * testsuite/17_intro/headers/c++2014/all_attributes.cc: Likewise. * testsuite/17_intro/headers/c++2017/all_attributes.cc: Likewise. * testsuite/17_intro/headers/c++2020/all_attributes.cc: Likewise. Co-Authored-By: Iain Sandoe <iain@sandoe.co.uk> From-SVN: r266863
2018-12-04PR libstdc++/88341 - Complex norm doesn't compile with C++11Edward Smith-Rowland3-2/+35
2018-12-03 Edward Smith-Rowland <3dw4rd@verizon.net> PR libstdc++/88341 - Complex norm doesn't compile with C++11 * include/std/complex (_S_do_it): Make C++20 constexpr. * testsuite/26_numerics/complex/value_operations/pr88341.cc: New test. From-SVN: r266788
2018-11-30Implement P0457R2 String Prefix and Suffix Checking.Edward Smith-Rowland11-1/+523
2018-11-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement P0457R2 String Prefix and Suffix Checking. * include/bits/basic_string.h: Add starts_with, ends_with members. * include/std/string_view: Ditto. * testsuite/21_strings/basic_string/operations/starts_with/ char/1.cc: New test. * testsuite/21_strings/basic_string/operations/starts_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string/operations/ends_with/ char/1.cc: New test. * testsuite/21_strings/basic_string/operations/ends_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/starts_with/ char/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/starts_with/ wchar_t/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/ends_with/ char/1.cc: New test. * testsuite/21_strings/basic_string_view/operations/ends_with/ wchar_t/1.cc: New test. From-SVN: r266674
2018-11-30The remainder of the Pre-emptively support P0646R1 for std container erasure.Edward Smith-Rowland1-2/+6
From-SVN: r266673
2018-11-30Pre-emptively support P0646R1 for std container erasure.Edward Smith-Rowland19-57/+117
2018-11-30 Edward Smith-Rowland <3dw4rd@verizon.net> Pre-emptively support P0646R1 for std container erasure. * include/bits/erase_if.h: Accumulate and return number of erased nodes. * include/std/forward_list (): Return number of erased items. * include/std/list (): Ditto. * include/std/map (): Ditto. * include/std/set (): Ditto. * include/std/string (): Ditto. * include/std/unordered_map (): Ditto. * include/std/unordered_set (): Ditto. * include/std/vector (): Ditto. * testsuite/21_strings/basic_string/erasure.cc: Test number of erasures. * testsuite/23_containers/deque/erasure.cc: Ditto. * testsuite/23_containers/forward_list/erasure.cc: Ditto. * testsuite/23_containers/list/erasure.cc: Ditto. * testsuite/23_containers/map/erasure.cc: Ditto. * testsuite/23_containers/set/erasure.cc: Ditto. * testsuite/23_containers/unordered_map/erasure.cc: Ditto. * testsuite/23_containers/unordered_set/erasure.cc: Ditto. * testsuite/23_containers/vector/erasure.cc: Ditto. From-SVN: r266672
2018-11-29Only include bits/stl_algo.h for C++20.Edward Smith-Rowland4-3/+16
2018-11-29 Edward Smith-Rowland <3dw4rd@verizon.net> Only include bits/stl_algo.h for C++20. * include/std/deque: Only include bits/stl_algo.h for C++20. * include/std/string: Ditto. * include/std/vector: Ditto. From-SVN: r266624
2018-11-29Fix erasure goofs.Edward Smith-Rowland15-5/+49
2018-11-29 Edward Smith-Rowland <3dw4rd@verizon.net> Fix erasure goofs. * include/experimental/deque: Make inline. * include/std/deque: Include bits/stl_algo.h. (erase, erase_if): Make inline. * include/std/string: Include bits/stl_algo.h. * include/std/unordered_set: Add erase, erase_if! * include/std/vector: Include bits/stl_algo.h. * testsuite/21_strings/basic_string/erasure.cc: Add { dg-options "-std=gnu++2a" }. * testsuite/23_containers/deque/erasure.cc: Ditto. * testsuite/23_containers/forward_list/erasure.cc: Ditto. * testsuite/23_containers/list/erasure.cc: Ditto. * testsuite/23_containers/map/erasure.cc: Ditto. * testsuite/23_containers/set/erasure.cc: Ditto. * testsuite/23_containers/unordered_map/erasure.cc: Ditto. * testsuite/23_containers/unordered_set/erasure.cc: Ditto. * testsuite/23_containers/vector/erasure.cc: Ditto. From-SVN: r266616
2018-11-29PR libstdc++/88119 use alignof in std::alignment_of, not __alignof__Jonathan Wakely4-14/+29
Now that __alignof__ and alignof sometimes disagree it matters which one we use. The standard says that std::alignment_of<T>::value equals alignof(T), so we need to use that. Change the only uses of alignment_of to use __alignof__ to avoid a change in alignment. PR libstdc++/88119 * include/ext/aligned_buffer.h (__aligned_membuf): Add comment. (__aligned_buffer): Use __alignof__ instead of std::alignment_of. * include/std/type_traits (alignment_of): Use alignof instead of __alignof__. * testsuite/20_util/alignment_of/value.cc: Fix test to check values match alignof not __alignof__, as required by the standard. From-SVN: r266613
2018-11-29PR libstdc++/86910 fix filesystem::create_directoriesJonathan Wakely5-23/+194
Implement the proposed semantics from P1164R0, which reverts the changes of LWG 2935. This means that failure to create a directory because a non-directory already exists with that name will be reported as an error. While rewriting the function, also fix PR 87846, which is a result of the C++17 changes to how a trailing slash on a path affects the last component of a path. PR libstdc++/86910 PR libstdc++/87846 * src/filesystem/ops.cc (experimental::create_directories): Report an error when the path resolves to an existing non-directory (P1164). * src/filesystem/std-ops.cc (create_directories): Likewise. Handle empty filenames due to trailing slashes. * testsuite/27_io/filesystem/operations/create_directories.cc: Test when some component of the path exists and is not a directory. Test trailing slashes. * testsuite/experimental/filesystem/operations/create_directories.cc: Likewise. From-SVN: r266598
2018-11-28Fix undefined references in libstdc++fs.aJonathan Wakely2-24/+32
The recent patch for PR 83306 removed the fs_err_concat functions that were used by the experimental::filesystem::filesystem_error class as well. This fixes it by doing the string generation directly in filesystem_error::_M_gen_what() instead of using the removed function. PR libstdc++/83306 * src/filesystem/path.cc (filesystem_error::_M_gen_what()): Create string directly, instead of calling fs_err_concat. From-SVN: r266569
2018-11-28PR libstdc++/83511 add default argument to basic_string_view::substrJonathan Wakely7-2/+168
PR libstdc++/83511 * include/std/string_view (basic_string_view::substr): Add default argument to first parameter. * include/experimental/string_view (basic_string_view::substr): Likewise. * testsuite/21_strings/basic_string_view/operations/substr/char/ 83511.cc: New test. * testsuite/21_strings/basic_string_view/operations/substr/wchar_t/ 83511.cc: New test. * testsuite/experimental/string_view/operations/substr/char/83511.cc: New test. * testsuite/experimental/string_view/operations/substr/wchar_t/83511.cc: New test. From-SVN: r266568
2018-11-28Implement uniform container erasure for C++20.Edward Smith-Rowland26-26/+720
2018-11-28 Edward Smith-Rowland <3dw4rd@verizon.net> Implement uniform container erasure for C++20. * include/Makefile.am: Move erase_if.h. * include/Makefile.in: Move erase_if.h. * include/experimental/bits/erase_if.h: Move ... * include/bits/erase_if.h: ... here. * include/experimental/map: Move erase_if.h. * include/experimental/set: Move erase_if.h. * include/experimental/unordered_map: Move erase_if.h. * include/experimental/unordered_set: Move erase_if.h. * include/std/deque (erase_if, erase): New functions. * include/std/forward_list: Ditto. * include/std/list: Ditto. * include/std/map: Ditto. * include/std/set: Ditto. * include/std/string: Ditto. * include/std/unordered_map: Ditto. * include/std/unordered_set: Ditto. * include/std/vector: Ditto. * testsuite/21_strings/basic_string/erasure.cc: New test. * testsuite/23_containers/deque/erasure.cc: New test. * testsuite/23_containers/forward_list/erasure.cc: New test. * testsuite/23_containers/list/erasure.cc: New test. * testsuite/23_containers/map/erasure.cc: New test. * testsuite/23_containers/set/erasure.cc: New test. * testsuite/23_containers/unordered_map/erasure.cc: New test. * testsuite/23_containers/unordered_set/erasure.cc: New test. * testsuite/23_containers/vector/erasure.cc: New test. From-SVN: r266567
2018-11-28Apply resolution for LWG DR 3096Jonathan Wakely4-2/+37
Add fix for "path::lexically_relative is confused by trailing slashes". * doc/xml/manual/intro.xml: Document LWG 3096 change. * src/filesystem/std-path.cc (path::lexically_relative(const path&)): Treat a final empty element equivalently to a final dot element. * testsuite/27_io/filesystem/path/generation/relative.cc: Add checks for the examples in the DR. From-SVN: r266566
2018-11-28PR libstdc++/83306 make filesystem_error no-throw copyableJonathan Wakely5-52/+302
The class API provides no way to modify the members, so we can share them between copies of the same object. Copying becomes a simple reference count update, which doesn't throw. Also adjust the what() string to allow distinguishing between an empty path passed to the constructor, and no path. PR libstdc++/83306 * include/bits/fs_path.h (filesystem_error): Move data members into pimpl class owned by shared_ptr. Remove inline definitions of member functions. * src/filesystem/std-path.cc (filesystem_error::_Impl): Define. (filesystem_error): Define member functions. * testsuite/27_io/filesystem/filesystem_error/cons.cc: New test. * testsuite/27_io/filesystem/filesystem_error/copy.cc: New test. From-SVN: r266565
2018-11-28Update C++17 library status docsJonathan Wakely5-20/+48
* doc/xml/manual/status_cxx2017.xml: Update C++17 status. * doc/html/*: Regenerate. From-SVN: r266559
2018-11-27Clean up temporary files created by std::filesystem testsuiteJonathan Wakely3-0/+7
* testsuite/27_io/filesystem/operations/canonical.cc: Remove directory created by test. * testsuite/27_io/filesystem/operations/symlink_status.cc: Remove symlink created by test. From-SVN: r266535
2018-11-27PR libstdc++/67843 set shared_ptr lock policy at build-timeJonathan Wakely10-21/+224
This resolves a longstanding issue where the lock policy for shared_ptr reference counting depends on compilation options when the header is included, so that different -march options can cause ABI changes. For example, objects compiled with -march=armv7 will use atomics to synchronize reference counts, and objects compiled with -march=armv5t will use a mutex. That means the shared_ptr control block will have a different layout in different objects, causing ODR violations and undefined behaviour. This was the root cause of PR libstdc++/42734 as well as PR libstdc++/67843. The solution is to decide on the lock policy at build time, when libstdc++ is configured. The configure script checks for the availability of the necessary atomic built-ins for the target and fixes that choice permanently. Different -march flags used to compile user code will not cause changes to the lock policy. This results in an ABI change for certain compilations, but only where there was already an ABI incompatibility between the libstdc++.so library and objects built with an incompatible -march option. In general, this means a more stable ABI that isn't silently altered when -march flags make addition atomic ops available. To force a target to use "atomic" or "mutex" the new configure option --with-libstdcxx-lock-policy can be used. In order to turn ODR violations into linker errors, the uses of shared_ptr in filesystem directory iterators have been replaced with __shared_ptr, and explicit instantiations are declared. This ensures that object files using those types cannot link to libstdc++ libs unless they use the same lock policy. PR libstdc++/67843 * acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add new macro that defines _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_ENABLE_LOCK_POLICY. * doc/xml/manual/configure.xml: Document new configure option. * include/bits/fs_dir.h (directory_iterator): Use __shared_ptr instead of shared_ptr. (recursive_directory_iterator): Likewise. (__shared_ptr<_Dir>): Add explicit instantiation declaration. (__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise. * include/bits/shared_ptr_base.h (__allocate_shared, __make_shared): Add default template argument for _Lock_policy template parameter. * include/ext/concurrence.h (__default_lock_policy): Check macro _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY instead of checking if the current target supports the builtins for compare-and-swap. * src/filesystem/std-dir.cc (__shared_ptr<_Dir>): Add explicit instantiation definition. (__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise. (directory_iterator, recursive_directory_iterator): Use __make_shared instead of make_shared. From-SVN: r266533
2018-11-27re PR libstdc++/88199 (memory leak on unordered container move assignment)François Dumont3-112/+169
2018-11-27 François Dumont <fdumont@gcc.gnu.org> PR libstdc++/88199 * include/bits/hashtable.h (_Hashtable<>::_M_assign_elements): New. (_Hashtable<>::operator=(const _Hashtable&)): Use latter. (_Hashtable<>::_M_move_assign(_Hashtable&&, false_type)): Likewise. * testsuite/23_containers/unordered_set/allocator/move_assign.cc (test03): New. From-SVN: r266528
2018-11-26Only use __float128 in test if availableJonathan Wakely2-0/+7
* testsuite/26_numerics/complex/requirements/more_constexpr.cc: Fix failure on targets without __float128. From-SVN: r266450
2018-11-23Implement P0415 More constexpr for std::complex.Edward Smith-Rowland7-154/+524
2018-11-23 Edward Smith-Rowland <3dw4rd@verizon.net> Implement P0415 More constexpr for std::complex. * include/std/complex (conj(complex<Tp>), norm(complex<Tp>)): Constexpr; (real(Tp), imag(Tp)): Constexpr; (operator@=(Tp), operator@=(complex<Tp>)): Constexpr; (operator@(Tp,complex<Tp>), operator@(complex<Tp>,Tp) operator@(complex<Tp>,complex<Tp>)): Constexpr. * testsuite/26_numerics/complex/comparison_operators/ more_constexpr.cc: New test. * testsuite/26_numerics/complex/operators/more_constexpr.cc: New test. * testsuite/26_numerics/complex/requirements/ more_constexpr.cc: New test. * testsuite/26_numerics/complex/value_operations/ more_constexpr.cc: New test. * testsuite/26_numerics/headers/complex/synopsis.cc: Add _GLIBCXX20_CONSTEXPR to applicable operators; Add missing proj(). * testsuite/26_numerics/headers/complex/synopsis.cc: Add _GLIBCXX20_CONSTEXPR to relevant decls. From-SVN: r266416
2018-11-23PR libstdc++/65229 fix pretty printer for std::bitset<0>Martin Sebor3-4/+21
2018-11-23 Martin Sebor <msebor@redhat.com> Jonathan Wakely <jwakely@redhat.com> PR libstdc++/65229 * python/libstdcxx/v6/printers.py (StdBitsetPrinter): Handle exception thrown for std::bitset<0>. * testsuite/libstdc++-prettyprinters/simple.cc: Test std::bitset<0>. Co-Authored-By: Jonathan Wakely <jwakely@redhat.com> From-SVN: r266409
2018-11-23PR libstdc++/87308 adjust regex used in std::any pretty printerJonathan Wakely3-1/+12
The pretty printer for std::any fails when the contained value is a locally-defined type, because the name in the debuginfo has cv-qualifiers and ptr-declarators in different positions. The unexpected format confuses the printer. This makes the printer's regex handle either format. This isn't a complete fix because looking up the contained type fails when there are two types with the same name (defined in different local scopes). This applies to all closure types defined in a given function, as they all appear as "func()::lambda" in the debuginfo names. PR libstdc++/87308 (partial) * python/libstdcxx/v6/printers.py (StdExpAnyPrinter): Adjust regex to work around PR 88166. * testsuite/libstdc++-prettyprinters/cxx17.cc: Test std::any containing a local type. From-SVN: r266408
2018-11-22Improve relocationMarc Glisse6-9/+45
2018-11-22 Marc Glisse <marc.glisse@inria.fr> PR libstdc++/87106 * include/bits/stl_algobase.h: Include <type_traits>. (__niter_base): Add noexcept specification. * include/bits/stl_deque.h: Include <bits/stl_uninitialized.h>. (__is_trivially_relocatable): Specialize for deque. * include/bits/stl_iterator.h: Include <type_traits>. (__niter_base): Add noexcept specification. * include/bits/stl_uninitialized.h (__is_trivially_relocatable): Add parameter for meta-programming. (__relocate_a_1, __relocate_a): Add noexcept specification. * include/bits/stl_vector.h (__use_relocate): Test __relocate_a. From-SVN: r266386
2018-11-22PR libstdc++/87520 Always pass type-punned type_info referenceJonathan Wakely2-13/+24
The implementations of std::make_shared for -frtti and -fno-rtti are not compatible, because they pass different arguments to _Sp_counted_ptr_inplace::_M_get_deleter and so can't interoperate. Either the argument doesn't match the expected value, and so the shared_ptr::_M_ptr member is never set, or the type-punned reference is treated as a real std::type_info object and gets dereferenced. This patch removes the differences between -frtti and -fno-rtti, so that typeid is never used, and the type-punned reference is used in both cases. For backwards compatibility with existing code that passes typeid(_Sp_make_shared_tag) that still needs to be handled, but only after checking that the argument is not the type-punned reference (so it's safe to treat as a real std::type_info object). The reference is bound to an object of literal type, so that it doesn't need a guard variable to make its initialization thread-safe. This patch also fixes 87520 by ensuring that the type-punned reference is bound to "a region of storage of suitable size and alignment to contain an object of the reference's type" (as per the proposed resolution of Core DR 453). If all objects are built with the fixed version of GCC then -frtti and -fno-rtti can be mixed freely and std::make_shared will work correctly. If some objects are built with unfixed GCC versions then problems can still arise, depending on which template instantiations are kept by the linker. PR libstdc++/85930 PR libstdc++/87520 * include/bits/shared_ptr_base.h (_Sp_make_shared_tag::_S_ti) [__cpp_rtti]: Define even when RTTI is enabled. Use array of sizeof(type_info) so that type-punned reference binds to an object of the correct size as well as correct alignment. (_Sp_counted_ptr_inplace::_M_get_deleter) [__cpp_rtti]: Check for _S_ti() reference even when RTTI is enabled. (__shared_ptr(_Sp_make_shared_tag, const _Alloc&, _Args&&...)) [__cpp_rtti]: Pass _S_ti() instead of typeid(_Sp_make_shared_tag). From-SVN: r266376
2018-11-21re PR c++/87386 (Error message for static_assert show wrong range)Jakub Jelinek8-7/+19
PR c++/87386 * parser.c (cp_parser_primary_expression): Use id_expression.get_location () instead of id_expr_token->location. Adjust the range from id_expr_token->location to id_expressio.get_finish (). (cp_parser_operator_function_id): Pass location of the operator token down to cp_parser_operator. (cp_parser_operator): Add start_loc argument, always construct a location with caret at start_loc and range from start_loc to the finish of the last token. gcc/testsuite/ * g++.dg/diagnostic/pr87386.C: New test. * g++.dg/parse/error17.C: Adjust expected diagnostics. libstdc++-v3/ * testsuite/20_util/scoped_allocator/69293_neg.cc: Adjust expected line. * testsuite/20_util/uses_allocator/cons_neg.cc: Likewise. * testsuite/20_util/uses_allocator/69293_neg.cc: Likewise. * testsuite/experimental/propagate_const/requirements2.cc: Likewise. * testsuite/experimental/propagate_const/requirements3.cc: Likewise. * testsuite/experimental/propagate_const/requirements4.cc: Likewise. * testsuite/experimental/propagate_const/requirements5.cc: Likewise. From-SVN: r266359
2018-11-21PR libstdc++/88111 Make maximum block size depend on size_t widthJonathan Wakely3-6/+37
PR libstdc++/88111 * include/std/memory_resource (pool_options): Add Doxygen comments. * src/c++17/memory_resource.cc (pool_sizes): Only use suitable values on targets with 16-bit or 20-bit size_t type. (munge_options): Make default values depend on width of size_t type. From-SVN: r266353
2018-11-21PR libstdc++/88113 use size_type consistently instead of size_tJonathan Wakely2-12/+27
On 16-bit msp430-elf size_t is either 16 bits or 20 bits, and so can't represent all values of the uint32_t type used for bitset::size_type. Using the smaller of size_t and uint32_t for size_type ensures it fits in size_t. PR libstdc++/88113 * src/c++17/memory_resource.cc (bitset::size_type): Use the smaller of uint32_t and size_t. (bitset::size(), bitset::free(), bitset::update_next_word()) (bitset::max_blocks_per_chunk(), bitset::max_word_index()): Use size_type consistently instead of size_t. (chunk): Adjust static_assert checking sizeof(chunk). From-SVN: r266352
2018-11-20Housekeeping for the effective targets of optional's tests.Ville Voutilainen52-51/+106
* testsuite/20_util/optional/77288.cc: Adjust. * testsuite/20_util/optional/84601.cc: Likewise. * testsuite/20_util/optional/assignment/1.cc: Likewise. * testsuite/20_util/optional/assignment/2.cc: Likewise. * testsuite/20_util/optional/assignment/3.cc: Likewise. * testsuite/20_util/optional/assignment/4.cc: Likewise. * testsuite/20_util/optional/assignment/5.cc: Likewise. * testsuite/20_util/optional/assignment/6.cc: Likewise. * testsuite/20_util/optional/assignment/7.cc: Likewise. * testsuite/20_util/optional/assignment/8.cc: Likewise. * testsuite/20_util/optional/cons/77727.cc: Likewise. * testsuite/20_util/optional/cons/copy.cc: Likewise. * testsuite/20_util/optional/cons/deduction.cc: Likewise. * testsuite/20_util/optional/cons/default.cc: Likewise. * testsuite/20_util/optional/cons/move.cc: Likewise. * testsuite/20_util/optional/cons/trivial.cc: Likewise. * testsuite/20_util/optional/cons/value.cc: Likewise. * testsuite/20_util/optional/cons/value_neg.cc: Likewise. * testsuite/20_util/optional/constexpr/cons/default.cc: Likewise. * testsuite/20_util/optional/constexpr/cons/value.cc: Likewise. * testsuite/20_util/optional/constexpr/in_place.cc: Likewise. * testsuite/20_util/optional/constexpr/nullopt.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/1.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/4.cc: Likewise. * testsuite/20_util/optional/constexpr/observers/5.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/1.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/2.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/3.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/4.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/5.cc: Likewise. * testsuite/20_util/optional/constexpr/relops/6.cc: Likewise. * testsuite/20_util/optional/in_place.cc: Likewise. * testsuite/20_util/optional/make_optional.cc: Likewise. * testsuite/20_util/optional/nullopt.cc: Likewise. * testsuite/20_util/optional/observers/1.cc: Likewise. * testsuite/20_util/optional/observers/2.cc: Likewise. * testsuite/20_util/optional/observers/3.cc: Likewise. * testsuite/20_util/optional/observers/4.cc: Likewise. * testsuite/20_util/optional/observers/5.cc: Likewise. * testsuite/20_util/optional/observers/6.cc: Likewise. * testsuite/20_util/optional/relops/1.cc: Likewise. * testsuite/20_util/optional/relops/2.cc: Likewise. * testsuite/20_util/optional/relops/3.cc: Likewise. * testsuite/20_util/optional/relops/4.cc: Likewise. * testsuite/20_util/optional/relops/5.cc: Likewise. * testsuite/20_util/optional/relops/6.cc: Likewise. * testsuite/20_util/optional/relops/7.cc: Likewise. * testsuite/20_util/optional/requirements.cc: Likewise. * testsuite/20_util/optional/swap/1.cc: Likewise. * testsuite/20_util/optional/swap/2.cc: Likewise. * testsuite/20_util/optional/typedefs.cc: Likewise. From-SVN: r266310
2018-11-192018-11-19 François Dumont <fdumont@gcc.gnu.org>François Dumont2-33/+44
* include/ext/throw_allocator.h (annotate_base::insert(void*, size_t)): Use insert result to check for double insert attempt. (annotate_base::insert_construct(void*)): Likewise. (annotate_base::check_allocated(void*, size_t)): Return found iterator. (annotate_base::erase(void*, size_t)): Use latter method returned iterator. (annotate_base::check_constructed(void*, size_t)): Return found iterator. (annotate_base::erase_construct(void*)): Use latter method returned iterator. From-SVN: r266284