summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-10-13 08:43:22 +0100
committerRichard Sandiford <richard.sandiford@linaro.org>2017-10-13 08:43:22 +0100
commit246229fdf9230ca040aa990a3fbb42698f30ae5f (patch)
treeacad23f2376b0bc72e72dc3c8e5c4f89bd78a6f9 /libstdc++-v3
parentc2f1abac401810096970cf7dd60ca60484195a28 (diff)
parente3d0f65c14ffd7a63455dc1aa9d0405d25b327e4 (diff)
downloadgcc-246229fdf9230ca040aa990a3fbb42698f30ae5f.tar.gz
Merge trunk into sve
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog67
-rw-r--r--libstdc++-v3/include/Makefile.am1
-rw-r--r--libstdc++-v3/include/Makefile.in1
-rw-r--r--libstdc++-v3/include/bits/streambuf_iterator.h61
-rw-r--r--libstdc++-v3/include/c_compatibility/complex.h4
-rw-r--r--libstdc++-v3/include/precompiled/stdc++.h4
-rw-r--r--libstdc++-v3/include/std/charconv658
-rw-r--r--libstdc++-v3/src/c++98/complex_io.cc2
-rw-r--r--libstdc++-v3/testsuite/20_util/from_chars/1.cc80
-rw-r--r--libstdc++-v3/testsuite/20_util/from_chars/1_neg.cc38
-rw-r--r--libstdc++-v3/testsuite/20_util/from_chars/2.cc205
-rw-r--r--libstdc++-v3/testsuite/20_util/from_chars/requirements.cc61
-rw-r--r--libstdc++-v3/testsuite/20_util/to_chars/1.cc662
-rw-r--r--libstdc++-v3/testsuite/20_util/to_chars/1_neg.cc35
-rw-r--r--libstdc++-v3/testsuite/20_util/to_chars/2.cc78
-rw-r--r--libstdc++-v3/testsuite/20_util/to_chars/requirements.cc49
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc2
-rw-r--r--libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc2
-rw-r--r--libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/2.cc10
-rw-r--r--libstdc++-v3/testsuite/26_numerics/complex/c99.cc3
-rw-r--r--libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h33
-rw-r--r--libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h55
-rw-r--r--libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_gnu++11.h52
23 files changed, 2120 insertions, 43 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b2a8653c8b7..9a512b15b10 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,70 @@
+2017-10-10 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/bits/streambuf_iterator.h (istreambuf_iterator::equal):
+ Update comment about NAD issue.
+
+ PR libstdc++/59087
+ PR libstdc++/82417
+ * include/c_compatibility/complex.h [!C++98 && __STRICT_ANSI__]: Do
+ not include C library's <complex.h>.
+ * testsuite/26_numerics/complex/c99.cc: Depend on __STRICT_ANSI__.
+ * testsuite/26_numerics/headers/complex.h/std_c++11.h: New test.
+ * testsuite/26_numerics/headers/complex.h/std_gnu++11.h: New test.
+ * testsuite/26_numerics/headers/complex.h/std_c++98.h: New test.
+
+2017-10-05 Jonathan Wakely <jwakely@redhat.com>
+
+ * testsuite/20_util/to_chars/1.cc: Add dg-require-string-conversions.
+
+2017-10-04 Petr Ovtchenkov <ptr@void-ptr.info>
+ François Dumont <fdumont@gcc.gnu.org>
+
+ * include/bits/streambuf_iterator.h
+ (istreambuf_iterator<>::operator*()): Do not capture iterator state
+ in Debug assertion.
+ (istreambuf_iterator<>::operator++()): Likewise and remove _M_sbuf check.
+ (istreambuf_iterator<>::operator++(int)): Likewise.
+ (istreambuf_iterator<>::_M_get()): Remove _M_c assignment.
+ (istreambuf_iterator<>::_S_is_eof()): New.
+ (istreambuf_iterator<>::_M_at_eof()): Adapt, use latter.
+ (find(istreambuf_iterator<>, istreambuf_iterator<>, _CharT)):
+ Return an iterator with _M_c set to eof to capture streambuf state
+ on evaluation.
+ (testsuite/24_iterators/istreambuf_iterator/2.cc): Add checks.
+
+2017-10-03 Jakub Jelinek <jakub@redhat.com>
+
+ * include/std/charconv (__unsigned_least_t): Fix number of closing >s for
+ !_GLIBCXX_USE_INT128.
+
+2017-10-02 Jonathan Wakely <jwakely@redhat.com>
+
+ * include/Makefile.am: Add new <charconv> header.
+ * include/Makefile.in: Regenerate.
+ * include/precompiled/stdc++.h: Include <charconv>.
+ * include/std/charconv: New file.
+ (to_chars_result, to_chars, from_chars_result, from_chars): Define.
+ * testsuite/20_util/from_chars/1.cc: New test.
+ * testsuite/20_util/from_chars/1_neg.cc: New test.
+ * testsuite/20_util/from_chars/2.cc: New test.
+ * testsuite/20_util/from_chars/requirements.cc: New test.
+ * testsuite/20_util/to_chars/1.cc: New test.
+ * testsuite/20_util/to_chars/1_neg.cc: New test.
+ * testsuite/20_util/to_chars/2.cc: New test.
+ * testsuite/20_util/to_chars/requirements.cc: New test.
+
+2017-09-27 François Dumont <fdumont@gcc.gnu.org>
+
+ * testsuite/22_locale/money_get/get/char/22131.cc: Make test less
+ istreambuf_iterator implementation dependent.
+ * testsuite/22_locale/money_get/get/wchar_t/22131.cc: Likewise.
+
+2017-09-25 Uros Bizjak <ubizjak@gmail.com>
+
+ PR c/81854
+ * src/c++98/complex_io.cc (_GLIBCXX_LDBL_COMPAT): Declare alias
+ target as a C++ function with no prototype.
+
2017-09-21 Jonathan Wakely <jwakely@redhat.com>
* testsuite/25_algorithms/clamp/1.cc: Fix order of arguments and
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 87a41f59027..236c2d6059f 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -31,6 +31,7 @@ std_headers = \
${std_srcdir}/array \
${std_srcdir}/atomic \
${std_srcdir}/bitset \
+ ${std_srcdir}/charconv \
${std_srcdir}/chrono \
${std_srcdir}/codecvt \
${std_srcdir}/complex \
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 7bc46060adb..39dfede549b 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -324,6 +324,7 @@ std_headers = \
${std_srcdir}/array \
${std_srcdir}/atomic \
${std_srcdir}/bitset \
+ ${std_srcdir}/charconv \
${std_srcdir}/chrono \
${std_srcdir}/codecvt \
${std_srcdir}/complex \
diff --git a/libstdc++-v3/include/bits/streambuf_iterator.h b/libstdc++-v3/include/bits/streambuf_iterator.h
index f0451b12ce3..081afe59d84 100644
--- a/libstdc++-v3/include/bits/streambuf_iterator.h
+++ b/libstdc++-v3/include/bits/streambuf_iterator.h
@@ -95,7 +95,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// NB: This implementation assumes the "end of stream" value
// is EOF, or -1.
mutable streambuf_type* _M_sbuf;
- mutable int_type _M_c;
+ int_type _M_c;
public:
/// Construct end of input stream iterator.
@@ -122,28 +122,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
char_type
operator*() const
{
+ int_type __c = _M_get();
+
#ifdef _GLIBCXX_DEBUG_PEDANTIC
// Dereferencing a past-the-end istreambuf_iterator is a
// libstdc++ extension
- __glibcxx_requires_cond(!_M_at_eof(),
+ __glibcxx_requires_cond(!_S_is_eof(__c),
_M_message(__gnu_debug::__msg_deref_istreambuf)
._M_iterator(*this));
#endif
- return traits_type::to_char_type(_M_get());
+ return traits_type::to_char_type(__c);
}
/// Advance the iterator. Calls streambuf.sbumpc().
istreambuf_iterator&
operator++()
{
- __glibcxx_requires_cond(!_M_at_eof(),
+ __glibcxx_requires_cond(_M_sbuf &&
+ (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->sgetc())),
_M_message(__gnu_debug::__msg_inc_istreambuf)
._M_iterator(*this));
- if (_M_sbuf)
- {
- _M_sbuf->sbumpc();
- _M_c = traits_type::eof();
- }
+
+ _M_sbuf->sbumpc();
+ _M_c = traits_type::eof();
return *this;
}
@@ -151,22 +152,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
istreambuf_iterator
operator++(int)
{
- __glibcxx_requires_cond(!_M_at_eof(),
+ __glibcxx_requires_cond(_M_sbuf &&
+ (!_S_is_eof(_M_c) || !_S_is_eof(_M_sbuf->sgetc())),
_M_message(__gnu_debug::__msg_inc_istreambuf)
._M_iterator(*this));
istreambuf_iterator __old = *this;
- if (_M_sbuf)
- {
- __old._M_c = _M_sbuf->sbumpc();
- _M_c = traits_type::eof();
- }
+ __old._M_c = _M_sbuf->sbumpc();
+ _M_c = traits_type::eof();
return __old;
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 110 istreambuf_iterator::equal not const
- // NB: there is also number 111 (NAD, Future) pending on this function.
+ // NB: there is also number 111 (NAD) relevant to this function.
/// Return true both iterators are end or both are not end.
bool
equal(const istreambuf_iterator& __b) const
@@ -176,26 +175,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
int_type
_M_get() const
{
- const int_type __eof = traits_type::eof();
- int_type __ret = __eof;
- if (_M_sbuf)
- {
- if (!traits_type::eq_int_type(_M_c, __eof))
- __ret = _M_c;
- else if (!traits_type::eq_int_type((__ret = _M_sbuf->sgetc()),
- __eof))
- _M_c = __ret;
- else
- _M_sbuf = 0;
- }
+ int_type __ret = _M_c;
+ if (_M_sbuf && _S_is_eof(__ret) && _S_is_eof(__ret = _M_sbuf->sgetc()))
+ _M_sbuf = 0;
return __ret;
}
bool
_M_at_eof() const
+ { return _S_is_eof(_M_get()); }
+
+ static bool
+ _S_is_eof(int_type __c)
{
const int_type __eof = traits_type::eof();
- return traits_type::eq_int_type(_M_get(), __eof);
+ return traits_type::eq_int_type(__c, __eof);
}
};
@@ -373,13 +367,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
typedef typename __is_iterator_type::traits_type traits_type;
typedef typename __is_iterator_type::streambuf_type streambuf_type;
typedef typename traits_type::int_type int_type;
+ const int_type __eof = traits_type::eof();
if (__first._M_sbuf && !__last._M_sbuf)
{
const int_type __ival = traits_type::to_int_type(__val);
streambuf_type* __sb = __first._M_sbuf;
int_type __c = __sb->sgetc();
- while (!traits_type::eq_int_type(__c, traits_type::eof())
+ while (!traits_type::eq_int_type(__c, __eof)
&& !traits_type::eq_int_type(__c, __ival))
{
streamsize __n = __sb->egptr() - __sb->gptr();
@@ -396,11 +391,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__c = __sb->snextc();
}
- if (!traits_type::eq_int_type(__c, traits_type::eof()))
- __first._M_c = __c;
- else
- __first._M_sbuf = 0;
+ __first._M_c = __eof;
}
+
return __first;
}
diff --git a/libstdc++-v3/include/c_compatibility/complex.h b/libstdc++-v3/include/c_compatibility/complex.h
index b9af8472562..4b2343926ef 100644
--- a/libstdc++-v3/include/c_compatibility/complex.h
+++ b/libstdc++-v3/include/c_compatibility/complex.h
@@ -32,7 +32,9 @@
# include <ccomplex>
#endif
-#if _GLIBCXX_HAVE_COMPLEX_H
+#if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
+// For strict modes do not include the C library's <complex.h>, see PR 82417.
+#elif _GLIBCXX_HAVE_COMPLEX_H
# include_next <complex.h>
# ifdef _GLIBCXX_COMPLEX
// See PR56111, keep the macro in C++03 if possible.
diff --git a/libstdc++-v3/include/precompiled/stdc++.h b/libstdc++-v3/include/precompiled/stdc++.h
index 262743a3c1b..b2993cd379f 100644
--- a/libstdc++-v3/include/precompiled/stdc++.h
+++ b/libstdc++-v3/include/precompiled/stdc++.h
@@ -121,3 +121,7 @@
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif
+
+#if __cplusplus > 201402L
+#include <charconv>
+#endif
diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
new file mode 100644
index 00000000000..e5d6c106f70
--- /dev/null
+++ b/libstdc++-v3/include/std/charconv
@@ -0,0 +1,658 @@
+// Primitive numeric conversions (to_chars and from_chars) -*- C++ -*-
+
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file include/charconv
+ * This is a Standard C++ Library header.
+ */
+
+#ifndef _GLIBCXX_CHARCONV
+#define _GLIBCXX_CHARCONV 1
+
+#pragma GCC system_header
+
+#if __cplusplus >= 201402L
+
+#include <type_traits>
+#include <limits>
+#include <cctype>
+#include <bits/error_constants.h> // for std::errc
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ /// Result type of std::to_chars
+ struct to_chars_result
+ {
+ char* ptr;
+ errc ec;
+ };
+
+ /// Result type of std::from_chars
+ struct from_chars_result
+ {
+ const char* ptr;
+ errc ec;
+ };
+
+namespace __detail
+{
+ template<typename _Tp, typename... _Types>
+ using __is_one_of = __or_<is_same<_Tp, _Types>...>;
+
+ template<typename _Tp>
+ using __is_int_to_chars_type = __and_<is_integral<_Tp>,
+ __not_<__is_one_of<_Tp, bool, char16_t, char32_t
+#if _GLIBCXX_USE_WCHAR_T
+ , wchar_t
+#endif
+ >>>;
+
+ template<typename _Tp>
+ using __integer_to_chars_result_type
+ = enable_if_t<__is_int_to_chars_type<_Tp>::value, to_chars_result>;
+
+ template<typename _Tp>
+ using __unsigned_least_t
+ = conditional_t<(sizeof(_Tp) <= sizeof(int)), unsigned int,
+ conditional_t<(sizeof(_Tp) <= sizeof(long)), unsigned long,
+ conditional_t<(sizeof(_Tp) <= sizeof(long long)), unsigned long long,
+#if _GLIBCXX_USE_INT128
+ conditional_t<(sizeof(_Tp) <= sizeof(__int128)), unsigned __int128,
+#endif
+ void
+#if _GLIBCXX_USE_INT128
+ >
+#endif
+ >>>;
+
+ // Generic implementation for arbitrary bases.
+ template<typename _Tp>
+ constexpr unsigned
+ __to_chars_len(_Tp __value, int __base = 10) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ unsigned __n = 1;
+ const int __b2 = __base * __base;
+ const int __b3 = __b2 * __base;
+ const int __b4 = __b3 * __base;
+ for (;;)
+ {
+ if (__value < __base) return __n;
+ if (__value < __b2) return __n + 1;
+ if (__value < __b3) return __n + 2;
+ if (__value < __b4) return __n + 3;
+ __value /= (unsigned)__b4;
+ __n += 4;
+ }
+ }
+
+ template<typename _Tp>
+ constexpr unsigned
+ __to_chars_len_2(_Tp __value) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ constexpr size_t __nbits = __CHAR_BIT__ * sizeof(_Tp);
+
+ // N.B. __builtin_clzll is undefined if __value == 0, but std::to_chars
+ // handles zero values directly.
+
+ // For sizeof(_Tp) > 1 this is an order of magnitude faster than
+ // the generic __to_chars_len.
+ return __nbits
+ - (__builtin_clzll(__value)
+ - ((__CHAR_BIT__ * sizeof(long long)) - __nbits));
+ }
+
+ template<typename _Tp>
+ constexpr unsigned
+ __to_chars_len_8(_Tp __value) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ constexpr size_t __nbits = __CHAR_BIT__ * sizeof(_Tp);
+
+ if _GLIBCXX17_CONSTEXPR (__nbits <= 16)
+ {
+ return __value > 077777u ? 6u
+ : __value > 07777u ? 5u
+ : __value > 0777u ? 4u
+ : __value > 077u ? 3u
+ : __value > 07u ? 2u
+ : 1u;
+ }
+ else
+ return __to_chars_len(__value, 8);
+ }
+
+ // Generic implementation for arbitrary bases.
+ template<typename _Tp>
+ to_chars_result
+ __to_chars(char* __first, char* __last, _Tp __val, int __base) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ to_chars_result __res;
+
+ const unsigned __len = __to_chars_len(__val, __base);
+
+ if (__builtin_expect((__last - __first) < __len, 0))
+ {
+ __res.ptr = __last;
+ __res.ec = errc::value_too_large;
+ return __res;
+ }
+
+ unsigned __pos = __len - 1;
+
+ static constexpr char __digits[]
+ = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+ while (__val >= __base)
+ {
+ auto const __quo = __val / __base;
+ auto const __rem = __val % __base;
+ __first[__pos--] = __digits[__rem];
+ __val = __quo;
+ }
+ *__first = __digits[__val];
+
+ __res.ptr = __first + __len;
+ __res.ec = {};
+ return __res;
+ }
+
+ template<typename _Tp>
+ __integer_to_chars_result_type<_Tp>
+ __to_chars_16(char* __first, char* __last, _Tp __val) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ to_chars_result __res;
+
+ const unsigned __len = __to_chars_len(__val, 0x10);
+
+ if (__builtin_expect((__last - __first) < __len, 0))
+ {
+ __res.ptr = __last;
+ __res.ec = errc::value_too_large;
+ return __res;
+ }
+
+ static constexpr char __digits[513] =
+ "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"
+ "202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f"
+ "404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f"
+ "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f"
+ "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f"
+ "a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf"
+ "c0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
+ "e0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff";
+ unsigned __pos = __len - 1;
+ while (__val >= 0x100)
+ {
+ auto const __num = (__val % 0x100) * 2;
+ __val /= 0x100;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ __pos -= 2;
+ }
+ if (__val >= 0x10)
+ {
+ auto const __num = __val * 2;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ }
+ else
+ __first[__pos] = "0123456789abcdef"[__val];
+ __res.ptr = __first + __len;
+ __res.ec = {};
+ return __res;
+ }
+
+ template<typename _Tp>
+ __integer_to_chars_result_type<_Tp>
+ __to_chars_10(char* __first, char* __last, _Tp __val) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ to_chars_result __res;
+
+ const unsigned __len = __to_chars_len(__val, 10);
+
+ if (__builtin_expect((__last - __first) < __len, 0))
+ {
+ __res.ptr = __last;
+ __res.ec = errc::value_too_large;
+ return __res;
+ }
+
+ static constexpr char __digits[201] =
+ "0001020304050607080910111213141516171819"
+ "2021222324252627282930313233343536373839"
+ "4041424344454647484950515253545556575859"
+ "6061626364656667686970717273747576777879"
+ "8081828384858687888990919293949596979899";
+ unsigned __pos = __len - 1;
+ while (__val >= 100)
+ {
+ auto const __num = (__val % 100) * 2;
+ __val /= 100;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ __pos -= 2;
+ }
+ if (__val >= 10)
+ {
+ auto const __num = __val * 2;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ }
+ else
+ __first[__pos] = '0' + __val;
+ __res.ptr = __first + __len;
+ __res.ec = {};
+ return __res;
+ }
+
+ template<typename _Tp>
+ __integer_to_chars_result_type<_Tp>
+ __to_chars_8(char* __first, char* __last, _Tp __val) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ to_chars_result __res;
+
+ const unsigned __len = __to_chars_len_8(__val);
+
+ if (__builtin_expect((__last - __first) < __len, 0))
+ {
+ __res.ptr = __last;
+ __res.ec = errc::value_too_large;
+ return __res;
+ }
+
+ static constexpr char __digits[129] =
+ "00010203040506071011121314151617"
+ "20212223242526273031323334353637"
+ "40414243444546475051525354555657"
+ "60616263646566677071727374757677";
+ unsigned __pos = __len - 1;
+ while (__val >= 0100)
+ {
+ auto const __num = (__val % 0100) * 2;
+ __val /= 0100;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ __pos -= 2;
+ }
+ if (__val >= 010)
+ {
+ auto const __num = __val * 2;
+ __first[__pos] = __digits[__num + 1];
+ __first[__pos - 1] = __digits[__num];
+ }
+ else
+ __first[__pos] = '0' + __val;
+ __res.ptr = __first + __len;
+ __res.ec = {};
+ return __res;
+ }
+
+ template<typename _Tp>
+ __integer_to_chars_result_type<_Tp>
+ __to_chars_2(char* __first, char* __last, _Tp __val) noexcept
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ to_chars_result __res;
+
+ const unsigned __len = __to_chars_len_2(__val);
+
+ if (__builtin_expect((__last - __first) < __len, 0))
+ {
+ __res.ptr = __last;
+ __res.ec = errc::value_too_large;
+ return __res;
+ }
+
+ unsigned __pos = __len - 1;
+
+ while (__pos)
+ {
+ __first[__pos--] = '0' + (__val & 1);
+ __val >>= 1;
+ }
+ *__first = '0' + (__val & 1);
+
+ __res.ptr = __first + __len;
+ __res.ec = {};
+ return __res;
+ }
+
+} // namespace __detail
+
+ template<typename _Tp>
+ __detail::__integer_to_chars_result_type<_Tp>
+ to_chars(char* __first, char* __last, _Tp __value, int __base = 10)
+ {
+ __glibcxx_assert(2 <= __base && __base <= 36);
+
+ using _Up = __detail::__unsigned_least_t<_Tp>;
+ _Up __unsigned_val = __value;
+
+ if (__value == 0 && __first != __last)
+ {
+ *__first = '0';
+ return { __first + 1, errc{} };
+ }
+
+ if _GLIBCXX17_CONSTEXPR (std::is_signed<_Tp>::value)
+ if (__value < 0)
+ {
+ if (__builtin_expect(__first != __last, 1))
+ *__first++ = '-';
+ __unsigned_val = _Up(~__value) + _Up(1);
+ }
+
+ switch (__base)
+ {
+ case 16:
+ return __detail::__to_chars_16(__first, __last, __unsigned_val);
+ case 10:
+ return __detail::__to_chars_10(__first, __last, __unsigned_val);
+ case 8:
+ return __detail::__to_chars_8(__first, __last, __unsigned_val);
+ case 2:
+ return __detail::__to_chars_2(__first, __last, __unsigned_val);
+ default:
+ return __detail::__to_chars(__first, __last, __unsigned_val, __base);
+ }
+ }
+
+namespace __detail
+{
+ template<typename _Tp>
+ bool
+ __raise_and_add(_Tp& __val, int __base, unsigned char __c)
+ {
+ if (__builtin_mul_overflow(__val, __base, &__val)
+ || __builtin_add_overflow(__val, __c, &__val))
+ return false;
+ return true;
+ }
+
+ /// std::from_chars implementation for integers in base 2.
+ template<typename _Tp>
+ bool
+ __from_chars_binary(const char*& __first, const char* __last, _Tp& __val)
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ const ptrdiff_t __len = __last - __first;
+ int __i = 0;
+ while (__i < __len)
+ {
+ const unsigned char __c = (unsigned)__first[__i] - '0';
+ if (__c < 2)
+ __val = (__val << 1) | __c;
+ else
+ break;
+ __i++;
+ }
+ __first += __i;
+ return __i <= (sizeof(_Tp) * __CHAR_BIT__);
+ }
+
+ /// std::from_chars implementation for integers in bases 3 to 10.
+ template<typename _Tp>
+ bool
+ __from_chars_digit(const char*& __first, const char* __last, _Tp& __val,
+ int __base)
+ {
+ static_assert(is_integral<_Tp>::value, "implementation bug");
+ static_assert(is_unsigned<_Tp>::value, "implementation bug");
+
+ auto __matches = [__base](char __c) {
+ return '0' <= __c && __c <= ('0' + (__base - 1));
+ };
+
+ while (__first != __last)
+ {
+ const char __c = *__first;
+ if (__matches(__c))
+ {
+ if (!__raise_and_add(__val, __base, __c - '0'))
+ {
+ while (++__first != __last && __matches(*__first))
+ ;
+ return false;
+ }
+ __first++;
+ }
+ else
+ return true;
+ }
+ return true;
+ }
+
+ constexpr unsigned char
+ __from_chars_alpha_to_num(char __c)
+ {
+ switch (__c)
+ {
+ case 'a':
+ case 'A':
+ return 10;
+ case 'b':
+ case 'B':
+ return 11;
+ case 'c':
+ case 'C':
+ return 12;
+ case 'd':
+ case 'D':
+ return 13;
+ case 'e':
+ case 'E':
+ return 14;
+ case 'f':
+ case 'F':
+ return 15;
+ case 'g':
+ case 'G':
+ return 16;
+ case 'h':
+ case 'H':
+ return 17;
+ case 'i':
+ case 'I':
+ return 18;
+ case 'j':
+ case 'J':
+ return 19;
+ case 'k':
+ case 'K':
+ return 20;
+ case 'l':
+ case 'L':
+ return 21;
+ case 'm':
+ case 'M':
+ return 22;
+ case 'n':
+ case 'N':
+ return 23;
+ case 'o':
+ case 'O':
+ return 24;
+ case 'p':
+ case 'P':
+ return 25;
+ case 'q':
+ case 'Q':
+ return 26;
+ case 'r':
+ case 'R':
+ return 27;
+ case 's':
+ case 'S':
+ return 28;
+ case 't':
+ case 'T':
+ return 29;
+ case 'u':
+ case 'U':
+ return 30;
+ case 'v':
+ case 'V':
+ return 31;
+ case 'w':
+ case 'W':
+ return 32;
+ case 'x':
+ case 'X':
+ return 33;
+ case 'y':
+ case 'Y':
+ return 34;
+ case 'z':
+ case 'Z':
+ return 35;
+ }
+ return std::numeric_limits<unsigned char>::max();
+ }
+
+ /// std::from_chars implementation for integers in bases 11 to 26.
+ template<typename _Tp>
+ bool
+ __from_chars_alnum(const char*& __first, const char* __last, _Tp& __val,
+ int __base)
+ {
+ bool __valid = true;
+ while (__first != __last)
+ {
+ unsigned char __c = *__first;
+ if (std::isdigit(__c))
+ __c -= '0';
+ else
+ {
+ __c = __from_chars_alpha_to_num(__c);
+ if (__c >= __base)
+ break;
+ }
+
+ if (__builtin_expect(__valid, 1))
+ __valid = __raise_and_add(__val, __base, __c);
+ __first++;
+ }
+ return __valid;
+ }
+
+ template<typename _Tp>
+ using __integer_from_chars_result_type
+ = enable_if_t<__is_int_to_chars_type<_Tp>::value, from_chars_result>;
+
+} // namespace __detail
+
+ /// std::from_chars for integral types.
+ template<typename _Tp>
+ __detail::__integer_from_chars_result_type<_Tp>
+ from_chars(const char* __first, const char* __last, _Tp& __value,
+ int __base = 10)
+ {
+ __glibcxx_assert(2 <= __base && __base <= 36);
+
+ from_chars_result __res{__first, {}};
+
+ int __sign = 1;
+ if _GLIBCXX17_CONSTEXPR (std::is_signed<_Tp>::value)
+ if (__first != __last && *__first == '-')
+ {
+ __sign = -1;
+ ++__first;
+ }
+
+ using _Up = __detail::__unsigned_least_t<_Tp>;
+ _Up __val = 0;
+
+ const auto __start = __first;
+ bool __valid;
+ if (__base == 2)
+ __valid = __detail::__from_chars_binary(__first, __last, __val);
+ else if (__base <= 10)
+ __valid = __detail::__from_chars_digit(__first, __last, __val, __base);
+ else
+ __valid = __detail::__from_chars_alnum(__first, __last, __val, __base);
+
+ if (__builtin_expect(__first == __start, 0))
+ __res.ec = errc::invalid_argument;
+ else
+ {
+ __res.ptr = __first;
+ if (!__valid)
+ __res.ec = errc::result_out_of_range;
+ else
+ {
+ if _GLIBCXX17_CONSTEXPR (std::is_signed<_Tp>::value)
+ {
+ _Tp __tmp;
+ if (__builtin_mul_overflow(__val, __sign, &__tmp))
+ __res.ec = errc::result_out_of_range;
+ else
+ __value = __tmp;
+ }
+ else
+ {
+ if _GLIBCXX17_CONSTEXPR
+ (numeric_limits<_Up>::max() > numeric_limits<_Tp>::max())
+ {
+ if (__val > numeric_limits<_Tp>::max())
+ __res.ec = errc::result_out_of_range;
+ else
+ __value = __val;
+ }
+ else
+ __value = __val;
+ }
+ }
+ }
+ return __res;
+ }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+#endif // C++14
+#endif // _GLIBCXX_CHARCONV
diff --git a/libstdc++-v3/src/c++98/complex_io.cc b/libstdc++-v3/src/c++98/complex_io.cc
index bb09ca5e746..f55e322986e 100644
--- a/libstdc++-v3/src/c++98/complex_io.cc
+++ b/libstdc++-v3/src/c++98/complex_io.cc
@@ -95,7 +95,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
#ifdef _GLIBCXX_LONG_DOUBLE_COMPAT
#define _GLIBCXX_LDBL_COMPAT(dbl, ldbl) \
- extern "C" void ldbl (void) __attribute__ ((alias (#dbl), weak))
+ extern "C" void ldbl (...) __attribute__ ((alias (#dbl), weak))
_GLIBCXX_LDBL_COMPAT (_ZStlsIdcSt11char_traitsIcEERSt13basic_ostreamIT0_T1_ES6_RKSt7complexIT_E,
_ZStlsIecSt11char_traitsIcEERSt13basic_ostreamIT0_T1_ES6_RKSt7complexIT_E);
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/1.cc b/libstdc++-v3/testsuite/20_util/from_chars/1.cc
new file mode 100644
index 00000000000..b552195ae96
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/from_chars/1.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+#include <charconv>
+#include <string_view>
+
+template<typename I>
+bool
+check_from_chars(I expected, std::string_view s, int base = 0, char term = '\0')
+{
+ I val;
+ std::from_chars_result r = base == 0
+ ? std::from_chars(s.begin(), s.end(), val)
+ : std::from_chars(s.begin(), s.end(), val, base);
+ return r.ec == std::errc{} && (r.ptr == s.end() || *r.ptr == term) && val == expected;
+}
+
+#include <climits>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ // Using base 10
+ VERIFY( check_from_chars(123, "123") );
+ VERIFY( check_from_chars(-123, "-123") );
+ VERIFY( check_from_chars(123, "123a", 10, 'a') );
+ VERIFY( check_from_chars(123, "0000000000000000000000000000123") );
+ VERIFY( check_from_chars(123, "0000000000000000000000000000123a", 10, 'a') );
+}
+
+void
+test02()
+{
+ // "0x" parsed as "0" not as hex prefix:
+ VERIFY( check_from_chars(0, "0x1", 10, 'x') );
+ VERIFY( check_from_chars(0, "0X1", 10, 'X') );
+ VERIFY( check_from_chars(0, "0x1", 16, 'x') );
+ VERIFY( check_from_chars(0, "0X1", 16, 'X') );
+
+ VERIFY( check_from_chars(1155, "xx", 34) );
+ VERIFY( check_from_chars(1155, "XX", 34) );
+ VERIFY( check_from_chars(1155, "Xx", 34) );
+ VERIFY( check_from_chars(1224, "yy", 35) );
+ VERIFY( check_from_chars(1224, "YY", 35) );
+ VERIFY( check_from_chars(1224, "yY", 35) );
+ VERIFY( check_from_chars(1295, "zz", 36) );
+ VERIFY( check_from_chars(1295, "ZZ", 36) );
+ VERIFY( check_from_chars(1295, "Zz", 36) );
+
+ // Parsing stops at first invalid digit for the given base:
+ VERIFY( check_from_chars(1, "01234", 2, '2') );
+ VERIFY( check_from_chars(27, "1234", 4, '4') );
+ VERIFY( check_from_chars(1155, "xxy", 34, 'y') );
+ VERIFY( check_from_chars(1224, "yyz", 35, 'z') );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/1_neg.cc b/libstdc++-v3/testsuite/20_util/from_chars/1_neg.cc
new file mode 100644
index 00000000000..d826ba9712b
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/from_chars/1_neg.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <charconv>
+
+void
+test01(const char* first, const char* last)
+{
+#if _GLIBCXX_USE_WCHAR_T
+ wchar_t wc;
+ std::from_chars(first, last, wc); // { dg-error "no matching" }
+ std::from_chars(first, last, wc, 10); // { dg-error "no matching" }
+#endif
+
+ char16_t c16;
+ std::from_chars(first, last, c16); // { dg-error "no matching" }
+ std::from_chars(first, last, c16, 10); // { dg-error "no matching" }
+ char32_t c32;
+ std::from_chars(first, last, c32); // { dg-error "no matching" }
+ std::from_chars(first, last, c32, 10); // { dg-error "no matching" }
+}
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/2.cc b/libstdc++-v3/testsuite/20_util/from_chars/2.cc
new file mode 100644
index 00000000000..117cf74662a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/from_chars/2.cc
@@ -0,0 +1,205 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+#include <charconv>
+#include <string_view>
+#include <testsuite_hooks.h>
+
+// Test std::from_chars error handling.
+
+void
+test01()
+{
+ std::from_chars_result r;
+ int i = 999;
+ std::string_view s;
+
+ s = "";
+ r = std::from_chars(s.begin(), s.end(), i);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ VERIFY( i == 999 );
+
+ s = "*";
+ r = std::from_chars(s.begin(), s.end(), i);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ VERIFY( i == 999 );
+
+ s = "-";
+ r = std::from_chars(s.begin(), s.end(), i);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ VERIFY( i == 999 );
+
+ s = "-*";
+ r = std::from_chars(s.begin(), s.end(), i);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ VERIFY( i == 999 );
+
+ unsigned u = 888;
+ s = "-1";
+ r = std::from_chars(s.begin(), s.end(), u);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ s = "-a";
+ r = std::from_chars(s.begin(), s.end(), u);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ s = "-";
+ r = std::from_chars(s.begin(), s.end(), u);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == s.begin() );
+ VERIFY( u == 888 );
+
+ for (int base = 2; base <= 36; ++base)
+ {
+ const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz*";
+ const char buf[2] = { '-', digits[base] };
+ r = std::from_chars(buf, buf + 1, i, base);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == buf );
+ VERIFY( i == 999 );
+ r = std::from_chars(buf + 1, buf + 2, i, base);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == buf + 1 );
+ VERIFY( i == 999 );
+ r = std::from_chars(buf, buf + 2, i, base);
+ VERIFY( r.ec == std::errc::invalid_argument );
+ VERIFY( r.ptr == buf );
+ VERIFY( i == 999 );
+ }
+}
+
+void
+test02()
+{
+ std::from_chars_result r;
+ std::string_view s;
+
+ signed char c = -5;
+ s = "-10000001";
+ r = std::from_chars(s.begin(), s.end(), c, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "-10000001*";
+ r = std::from_chars(s.begin(), s.end(), c, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 9 );
+ s = "-10000001000*";
+ r = std::from_chars(s.begin(), s.end(), c, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 12 );
+ s = "-129";
+ r = std::from_chars(s.begin(), s.end(), c, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "-129*";
+ r = std::from_chars(s.begin(), s.end(), c, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 4 );
+ s = "-100";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "-100*";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 4 );
+ s = "-81";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "-81*";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 3 );
+ s = "128";
+ r = std::from_chars(s.begin(), s.end(), c, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "128*";
+ r = std::from_chars(s.begin(), s.end(), c, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 3 );
+ s = "80";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "80*";
+ r = std::from_chars(s.begin(), s.end(), c, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 2 );
+ VERIFY( c == -5 );
+
+ unsigned char uc = 9;
+ s = "100000000";
+ r = std::from_chars(s.begin(), s.end(), uc, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "100000000*";
+ r = std::from_chars(s.begin(), s.end(), uc, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 9 );
+ s = "100000000000*";
+ r = std::from_chars(s.begin(), s.end(), uc, 2);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 12 );
+ s = "256";
+ r = std::from_chars(s.begin(), s.end(), uc, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "256**";
+ r = std::from_chars(s.begin(), s.end(), uc, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 3 );
+ s = "256000**";
+ r = std::from_chars(s.begin(), s.end(), uc, 10);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 6 );
+ s = "100";
+ r = std::from_chars(s.begin(), s.end(), uc, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.end() );
+ s = "100**";
+ r = std::from_chars(s.begin(), s.end(), uc, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 3 );
+ s = "100000**";
+ r = std::from_chars(s.begin(), s.end(), uc, 16);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 6 );
+ VERIFY( uc == 9 );
+
+ unsigned long long ull = 123;
+ s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz****";
+ r = std::from_chars(s.begin(), s.end(), ull, 36);
+ VERIFY( r.ec == std::errc::result_out_of_range );
+ VERIFY( r.ptr == s.begin() + 42 );
+ VERIFY( ull == 123 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}
diff --git a/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc b/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc
new file mode 100644
index 00000000000..00b7d875664
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/from_chars/requirements.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <charconv>
+
+namespace std
+{
+ struct from_chars_result;
+
+ const char* from_chars_result::*pm2 = &from_chars_result::ptr;
+ errc from_chars_result::*pm1 = &from_chars_result::ec;
+
+ from_chars_result (*f1)(const char*, const char*, char&, int)
+ = &from_chars;
+ from_chars_result (*f2)(const char*, const char*, signed char&, int)
+ = &from_chars;
+ from_chars_result (*f3)(const char*, const char*, unsigned char&, int)
+ = &from_chars;
+ from_chars_result (*f4)(const char*, const char*, signed short&, int)
+ = &from_chars;
+ from_chars_result (*f5)(const char*, const char*, unsigned short&, int)
+ = &from_chars;
+ from_chars_result (*f6)(const char*, const char*, signed int&, int)
+ = &from_chars;
+ from_chars_result (*f7)(const char*, const char*, unsigned int&, int)
+ = &from_chars;
+ from_chars_result (*f8)(const char*, const char*, signed long&, int)
+ = &from_chars;
+ from_chars_result (*f9)(const char*, const char*, unsigned long&, int)
+ = &from_chars;
+ from_chars_result (*f10)(const char*, const char*, signed long long&, int)
+ = &from_chars;
+ from_chars_result (*f11)(const char*, const char*, unsigned long long&, int)
+ = &from_chars;
+}
+
+void bind()
+{
+ const char buf[1] = "";
+ int i;
+ auto [p, e] = std::from_chars(buf, buf + 1, i, 10);
+ const char** pa = &p;
+ std::errc* ea = &e;
+}
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/1.cc b/libstdc++-v3/testsuite/20_util/to_chars/1.cc
new file mode 100644
index 00000000000..12dfd3d49f3
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/to_chars/1.cc
@@ -0,0 +1,662 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+// { dg-require-string-conversions "" }
+
+#include <charconv>
+#include <string_view>
+
+template<typename I>
+bool
+check_to_chars(I val, std::string_view expected, int base = 0)
+{
+ // Space for minus sign, 64 binary digits, final '*', and null terminator:
+ char buf[67] = "******************************************************************";
+ std::to_chars_result r = base == 0
+ ? std::to_chars(buf, buf+sizeof(buf), val)
+ : std::to_chars(buf, buf+sizeof(buf), val, base);
+ return r.ec == std::errc{} && *r.ptr == '*' && std::string_view(buf, r.ptr - buf) == expected;
+}
+
+#include <string>
+#include <climits>
+#include <testsuite_hooks.h>
+
+// Using default base 10
+void
+test01()
+{
+ VERIFY( check_to_chars<char>(0, "0") );
+ VERIFY( check_to_chars<signed char>(0, "0") );
+ VERIFY( check_to_chars<unsigned char>(0, "0") );
+ VERIFY( check_to_chars<signed short>(0, "0") );
+ VERIFY( check_to_chars<unsigned short>(0, "0") );
+ VERIFY( check_to_chars<signed int>(0, "0") );
+ VERIFY( check_to_chars<unsigned int>(0, "0") );
+ VERIFY( check_to_chars<signed long>(0, "0") );
+ VERIFY( check_to_chars<unsigned long>(0, "0") );
+ VERIFY( check_to_chars<signed long long>(0, "0") );
+ VERIFY( check_to_chars<unsigned long long>(0, "0") );
+
+ VERIFY( check_to_chars<char>(1, "1") );
+ VERIFY( check_to_chars<signed char>(1, "1") );
+ VERIFY( check_to_chars<unsigned char>(1, "1") );
+ VERIFY( check_to_chars<signed short>(1, "1") );
+ VERIFY( check_to_chars<unsigned short>(1, "1") );
+ VERIFY( check_to_chars<signed int>(1, "1") );
+ VERIFY( check_to_chars<unsigned int>(1, "1") );
+ VERIFY( check_to_chars<signed long>(1, "1") );
+ VERIFY( check_to_chars<unsigned long>(1, "1") );
+ VERIFY( check_to_chars<signed long long>(1, "1") );
+ VERIFY( check_to_chars<unsigned long long>(1, "1") );
+
+ VERIFY( check_to_chars<char>(123, "123") );
+ VERIFY( check_to_chars<signed char>(123, "123") );
+ VERIFY( check_to_chars<unsigned char>(123, "123") );
+ VERIFY( check_to_chars<signed short>(123, "123") );
+ VERIFY( check_to_chars<unsigned short>(123, "123") );
+ VERIFY( check_to_chars<signed int>(123, "123") );
+ VERIFY( check_to_chars<unsigned int>(123, "123") );
+ VERIFY( check_to_chars<signed long>(123, "123") );
+ VERIFY( check_to_chars<unsigned long>(123, "123") );
+ VERIFY( check_to_chars<signed long long>(123, "123") );
+ VERIFY( check_to_chars<unsigned long long>(123, "123") );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-79, "-79") );
+ VERIFY( check_to_chars<signed char>(-79, "-79") );
+ VERIFY( check_to_chars<signed short>(-79, "-79") );
+ VERIFY( check_to_chars<signed int>(-79, "-79") );
+ VERIFY( check_to_chars<signed long>(-79, "-79") );
+ VERIFY( check_to_chars<signed long long>(-79, "-79") );
+
+ using std::to_string;
+
+ VERIFY( check_to_chars<char>(CHAR_MAX, to_string(CHAR_MAX)) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX, to_string(SCHAR_MAX)) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX, to_string(UCHAR_MAX)) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX, to_string(SHRT_MAX)) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX, to_string(USHRT_MAX)) );
+ VERIFY( check_to_chars<signed int>(INT_MAX, to_string(INT_MAX)) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX, to_string(UINT_MAX)) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX, to_string(LONG_MAX)) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX, to_string(ULONG_MAX)) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX, to_string(LLONG_MAX)) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX, to_string(ULLONG_MAX)) );
+
+ VERIFY( check_to_chars<char>(CHAR_MIN, to_string(CHAR_MIN)) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MIN, to_string(SCHAR_MIN)) );
+ VERIFY( check_to_chars<signed short>(SHRT_MIN, to_string(SHRT_MIN)) );
+ VERIFY( check_to_chars<signed int>(INT_MIN, to_string(INT_MIN)) );
+ VERIFY( check_to_chars<signed long>(LONG_MIN, to_string(LONG_MIN)) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MIN, to_string(LLONG_MIN)) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX/2, to_string(CHAR_MAX/2)) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX/2, to_string(SCHAR_MAX/2)) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX/2, to_string(UCHAR_MAX/2)) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX/2, to_string(SHRT_MAX/2)) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX/2, to_string(USHRT_MAX/2)) );
+ VERIFY( check_to_chars<signed int>(INT_MAX/2, to_string(INT_MAX/2)) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX/2, to_string(UINT_MAX/2)) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX/2, to_string(LONG_MAX/2)) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX/2, to_string(ULONG_MAX/2)) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX/2, to_string(LLONG_MAX/2)) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX/2, to_string(ULLONG_MAX/2)) );
+}
+
+// Using explicit base 10
+void
+test02()
+{
+ VERIFY( check_to_chars<char>(0, "0", 10) );
+ VERIFY( check_to_chars<signed char>(0, "0", 10) );
+ VERIFY( check_to_chars<unsigned char>(0, "0", 10) );
+ VERIFY( check_to_chars<signed short>(0, "0", 10) );
+ VERIFY( check_to_chars<unsigned short>(0, "0", 10) );
+ VERIFY( check_to_chars<signed int>(0, "0", 10) );
+ VERIFY( check_to_chars<unsigned int>(0, "0", 10) );
+ VERIFY( check_to_chars<signed long>(0, "0", 10) );
+ VERIFY( check_to_chars<unsigned long>(0, "0", 10) );
+ VERIFY( check_to_chars<signed long long>(0, "0", 10) );
+ VERIFY( check_to_chars<unsigned long long>(0, "0", 10) );
+
+ VERIFY( check_to_chars<char>(1, "1", 10) );
+ VERIFY( check_to_chars<signed char>(1, "1", 10) );
+ VERIFY( check_to_chars<unsigned char>(1, "1", 10) );
+ VERIFY( check_to_chars<signed short>(1, "1", 10) );
+ VERIFY( check_to_chars<unsigned short>(1, "1", 10) );
+ VERIFY( check_to_chars<signed int>(1, "1", 10) );
+ VERIFY( check_to_chars<unsigned int>(1, "1", 10) );
+ VERIFY( check_to_chars<signed long>(1, "1", 10) );
+ VERIFY( check_to_chars<unsigned long>(1, "1", 10) );
+ VERIFY( check_to_chars<signed long long>(1, "1", 10) );
+ VERIFY( check_to_chars<unsigned long long>(1, "1", 10) );
+
+ VERIFY( check_to_chars<char>(123, "123", 10) );
+ VERIFY( check_to_chars<signed char>(123, "123", 10) );
+ VERIFY( check_to_chars<unsigned char>(123, "123", 10) );
+ VERIFY( check_to_chars<signed short>(123, "123", 10) );
+ VERIFY( check_to_chars<unsigned short>(123, "123", 10) );
+ VERIFY( check_to_chars<signed int>(123, "123", 10) );
+ VERIFY( check_to_chars<unsigned int>(123, "123", 10) );
+ VERIFY( check_to_chars<signed long>(123, "123", 10) );
+ VERIFY( check_to_chars<unsigned long>(123, "123", 10) );
+ VERIFY( check_to_chars<signed long long>(123, "123", 10) );
+ VERIFY( check_to_chars<unsigned long long>(123, "123", 10) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-79, "-79", 10) );
+ VERIFY( check_to_chars<signed char>(-79, "-79", 10) );
+ VERIFY( check_to_chars<signed short>(-79, "-79", 10) );
+ VERIFY( check_to_chars<signed int>(-79, "-79", 10) );
+ VERIFY( check_to_chars<signed long>(-79, "-79", 10) );
+ VERIFY( check_to_chars<signed long long>(-79, "-79", 10) );
+
+ using std::to_string;
+
+ VERIFY( check_to_chars<char>(CHAR_MAX, to_string(CHAR_MAX), 10) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX, to_string(SCHAR_MAX), 10) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX, to_string(UCHAR_MAX), 10) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX, to_string(SHRT_MAX), 10) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX, to_string(USHRT_MAX), 10) );
+ VERIFY( check_to_chars<signed int>(INT_MAX, to_string(INT_MAX), 10) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX, to_string(UINT_MAX), 10) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX, to_string(LONG_MAX), 10) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX, to_string(ULONG_MAX), 10) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX, to_string(LLONG_MAX), 10) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX, to_string(ULLONG_MAX), 10) );
+
+ VERIFY( check_to_chars<char>(CHAR_MIN, to_string(CHAR_MIN), 10) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MIN, to_string(SCHAR_MIN), 10) );
+ VERIFY( check_to_chars<signed short>(SHRT_MIN, to_string(SHRT_MIN), 10) );
+ VERIFY( check_to_chars<signed int>(INT_MIN, to_string(INT_MIN), 10) );
+ VERIFY( check_to_chars<signed long>(LONG_MIN, to_string(LONG_MIN), 10) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MIN, to_string(LLONG_MIN), 10) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX/2, to_string(CHAR_MAX/2), 10) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX/2, to_string(SCHAR_MAX/2), 10) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX/2, to_string(UCHAR_MAX/2), 10) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX/2, to_string(SHRT_MAX/2), 10) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX/2, to_string(USHRT_MAX/2), 10) );
+ VERIFY( check_to_chars<signed int>(INT_MAX/2, to_string(INT_MAX/2), 10) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX/2, to_string(UINT_MAX/2), 10) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX/2, to_string(LONG_MAX/2), 10) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX/2, to_string(ULONG_MAX/2), 10) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX/2, to_string(LLONG_MAX/2), 10) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX/2, to_string(ULLONG_MAX/2), 10) );
+}
+
+// Using all bases
+void
+test03()
+{
+ // -2017 in all bases from [2,36]
+ const char* str2017[37] = { nullptr, nullptr,
+ "-11111100001",
+ "-2202201",
+ "-133201",
+ "-31032",
+ "-13201",
+ "-5611",
+ "-3741",
+ "-2681",
+ "-2017",
+ "-1574",
+ "-1201",
+ "-bc2",
+ "-a41",
+ "-8e7",
+ "-7e1",
+ "-6gb",
+ "-641",
+ "-5b3",
+ "-50h",
+ "-4c1",
+ "-43f",
+ "-3ig",
+ "-3c1",
+ "-35h",
+ "-2pf",
+ "-2kj",
+ "-2g1",
+ "-2bg",
+ "-277",
+ "-232",
+ "-1v1",
+ "-1s4",
+ "-1pb",
+ "-1mm",
+ "-1k1"
+ };
+ // -12345 in all bases from [2,36]
+ const char* str12345[37] = { nullptr, nullptr,
+ "-11000000111001",
+ "-121221020",
+ "-3000321",
+ "-343340",
+ "-133053",
+ "-50664",
+ "-30071",
+ "-17836",
+ "-12345",
+ "-9303",
+ "-7189",
+ "-5808",
+ "-46db",
+ "-39d0",
+ "-3039",
+ "-28c3",
+ "-221f",
+ "-1f3e",
+ "-1ah5",
+ "-16ki",
+ "-13b3",
+ "-107h",
+ "-la9",
+ "-jik",
+ "-i6l",
+ "-gp6",
+ "-fkp",
+ "-ejk",
+ "-dlf",
+ "-cq7",
+ "-c1p",
+ "-bb3",
+ "-an3",
+ "-a2p",
+ "-9ix"
+ };
+ // -23456 in all bases from [2,36]
+ const char* str23456[37] = { nullptr, nullptr,
+ "-101101110100000",
+ "-1012011202",
+ "-11232200",
+ "-1222311",
+ "-300332",
+ "-125246",
+ "-55640",
+ "-35152",
+ "-23456",
+ "-16694",
+ "-116a8",
+ "-a8a4",
+ "-8796",
+ "-6e3b",
+ "-5ba0",
+ "-4d2d",
+ "-4072",
+ "-37ia",
+ "-2icg",
+ "-2b3k",
+ "-24a4",
+ "-1l7j",
+ "-1gh8",
+ "-1cd6",
+ "-18i4",
+ "-154k",
+ "-11pk",
+ "-rpo",
+ "-q1q",
+ "-ock",
+ "-mt0",
+ "-lhq",
+ "-k9u",
+ "-j56",
+ "-i3k"
+ };
+ // INT_MIN in all bases from [2,36]
+ const char* strINT_MIN[37] = { nullptr, nullptr,
+ "-10000000000000000000000000000000",
+ "-12112122212110202102",
+ "-2000000000000000",
+ "-13344223434043",
+ "-553032005532",
+ "-104134211162",
+ "-20000000000",
+ "-5478773672",
+ "-2147483648",
+ "-a02220282",
+ "-4bb2308a8",
+ "-282ba4aab",
+ "-1652ca932",
+ "-c87e66b8",
+ "-80000000",
+ "-53g7f549",
+ "-3928g3h2",
+ "-27c57h33",
+ "-1db1f928",
+ "-140h2d92",
+ "-ikf5bf2",
+ "-ebelf96",
+ "-b5gge58",
+ "-8jmdnkn",
+ "-6oj8ioo",
+ "-5ehnckb",
+ "-4clm98g",
+ "-3hk7988",
+ "-2sb6cs8",
+ "-2d09uc2",
+ "-2000000",
+ "-1lsqtl2",
+ "-1d8xqrq",
+ "-15v22un",
+ "-zik0zk"
+ };
+
+ for (int base = 2; base <= 36; ++base)
+ {
+ VERIFY( check_to_chars<char>(0, "0", base) );
+ VERIFY( check_to_chars<signed char>(0, "0", base) );
+ VERIFY( check_to_chars<unsigned char>(0, "0", base) );
+ VERIFY( check_to_chars<signed short>(0, "0", base) );
+ VERIFY( check_to_chars<unsigned short>(0, "0", base) );
+ VERIFY( check_to_chars<signed int>(0, "0", base) );
+ VERIFY( check_to_chars<unsigned int>(0, "0", base) );
+ VERIFY( check_to_chars<signed long>(0, "0", base) );
+ VERIFY( check_to_chars<unsigned long>(0, "0", base) );
+ VERIFY( check_to_chars<signed long long>(0, "0", base) );
+ VERIFY( check_to_chars<unsigned long long>(0, "0", base) );
+
+ VERIFY( check_to_chars<char>(1, "1", base) );
+ VERIFY( check_to_chars<signed char>(1, "1", base) );
+ VERIFY( check_to_chars<unsigned char>(1, "1", base) );
+ VERIFY( check_to_chars<signed short>(1, "1", base) );
+ VERIFY( check_to_chars<unsigned short>(1, "1", base) );
+ VERIFY( check_to_chars<signed int>(1, "1", base) );
+ VERIFY( check_to_chars<unsigned int>(1, "1", base) );
+ VERIFY( check_to_chars<signed long>(1, "1", base) );
+ VERIFY( check_to_chars<unsigned long>(1, "1", base) );
+ VERIFY( check_to_chars<signed long long>(1, "1", base) );
+ VERIFY( check_to_chars<unsigned long long>(1, "1", base) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-1, "-1", base) );
+ VERIFY( check_to_chars<signed char>(-1, "-1", base) );
+ VERIFY( check_to_chars<signed short>(-1, "-1", base) );
+ VERIFY( check_to_chars<signed int>(-1, "-1", base) );
+ VERIFY( check_to_chars<signed long>(-1, "-1", base) );
+ VERIFY( check_to_chars<signed long long>(-1, "-1", base) );
+
+ if (base > 2)
+ {
+ VERIFY( check_to_chars<char>(2, "2", base) );
+ VERIFY( check_to_chars<signed char>(2, "2", base) );
+ VERIFY( check_to_chars<unsigned char>(2, "2", base) );
+ VERIFY( check_to_chars<signed short>(2, "2", base) );
+ VERIFY( check_to_chars<unsigned short>(2, "2", base) );
+ VERIFY( check_to_chars<signed int>(2, "2", base) );
+ VERIFY( check_to_chars<unsigned int>(2, "2", base) );
+ VERIFY( check_to_chars<signed long>(2, "2", base) );
+ VERIFY( check_to_chars<unsigned long>(2, "2", base) );
+ VERIFY( check_to_chars<signed long long>(2, "2", base) );
+ VERIFY( check_to_chars<unsigned long long>(2, "2", base) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-2, "-2", base) );
+ VERIFY( check_to_chars<signed char>(-2, "-2", base) );
+ VERIFY( check_to_chars<signed short>(-2, "-2", base) );
+ VERIFY( check_to_chars<signed int>(-2, "-2", base) );
+ VERIFY( check_to_chars<signed long>(-2, "-2", base) );
+ VERIFY( check_to_chars<signed long long>(-2, "-2", base) );
+ }
+
+ VERIFY( check_to_chars(2017u, str2017[base]+1, base) );
+ VERIFY( check_to_chars(2017, str2017[base]+1, base) );
+ VERIFY( check_to_chars(-2017, str2017[base], base) );
+ VERIFY( check_to_chars(12345u, str12345[base]+1, base) );
+ VERIFY( check_to_chars(12345, str12345[base]+1, base) );
+ VERIFY( check_to_chars(-12345, str12345[base], base) );
+ VERIFY( check_to_chars(23456u, str23456[base]+1, base) );
+ VERIFY( check_to_chars(23456, str23456[base]+1, base) );
+ VERIFY( check_to_chars(-23456, str23456[base], base) );
+ VERIFY( check_to_chars(INT_MAX + 1ull, strINT_MIN[base]+1, base) );
+ VERIFY( check_to_chars(INT_MAX + 1ll, strINT_MIN[base]+1, base) );
+ VERIFY( check_to_chars(INT_MIN, strINT_MIN[base], base) );
+ }
+
+ VERIFY( check_to_chars(1155, "xx", 34) );
+ VERIFY( check_to_chars(1224, "yy", 35) );
+ VERIFY( check_to_chars(1295, "zz", 36) );
+}
+
+#include <sstream>
+#include <ios>
+
+// base 8
+void
+test04()
+{
+ auto to_string = [](auto val) {
+ std::ostringstream ss;
+ ss << std::oct;
+ if (val < 0)
+ ss << '-' << (~val + 1ull);
+ else if (sizeof(val) == 1)
+ ss << (int)val;
+ else
+ ss << val;
+ return ss.str();
+ };
+
+ VERIFY( check_to_chars<char>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<signed char>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<unsigned char>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<signed short>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<unsigned short>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<signed int>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<unsigned int>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<signed long>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<unsigned long>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<signed long long>(123, to_string(123), 8) );
+ VERIFY( check_to_chars<unsigned long long>(123, to_string(123), 8) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-79, to_string(-79), 8) );
+ VERIFY( check_to_chars<signed char>(-79, to_string(-79), 8) );
+ VERIFY( check_to_chars<signed short>(-79, to_string(-79), 8) );
+ VERIFY( check_to_chars<signed int>(-79, to_string(-79), 8) );
+ VERIFY( check_to_chars<signed long>(-79, to_string(-79), 8) );
+ VERIFY( check_to_chars<signed long long>(-79, to_string(-79), 8) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX, to_string(CHAR_MAX), 8) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX, to_string(SCHAR_MAX), 8) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX, to_string(UCHAR_MAX), 8) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX, to_string(SHRT_MAX), 8) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX, to_string(USHRT_MAX), 8) );
+ VERIFY( check_to_chars<signed int>(INT_MAX, to_string(INT_MAX), 8) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX, to_string(UINT_MAX), 8) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX, to_string(LONG_MAX), 8) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX, to_string(ULONG_MAX), 8) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX, to_string(LLONG_MAX), 8) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX, to_string(ULLONG_MAX), 8) );
+
+ VERIFY( check_to_chars<char>(CHAR_MIN, to_string(CHAR_MIN), 8) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MIN, to_string(SCHAR_MIN), 8) );
+ VERIFY( check_to_chars<signed short>(SHRT_MIN, to_string(SHRT_MIN), 8) );
+ VERIFY( check_to_chars<signed int>(INT_MIN, to_string(INT_MIN), 8) );
+ VERIFY( check_to_chars<signed long>(LONG_MIN, to_string(LONG_MIN), 8) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MIN, to_string(LLONG_MIN), 8) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX/2, to_string(CHAR_MAX/2), 8) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX/2, to_string(SCHAR_MAX/2), 8) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX/2, to_string(UCHAR_MAX/2), 8) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX/2, to_string(SHRT_MAX/2), 8) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX/2, to_string(USHRT_MAX/2), 8) );
+ VERIFY( check_to_chars<signed int>(INT_MAX/2, to_string(INT_MAX/2), 8) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX/2, to_string(UINT_MAX/2), 8) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX/2, to_string(LONG_MAX/2), 8) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX/2, to_string(ULONG_MAX/2), 8) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX/2, to_string(LLONG_MAX/2), 8) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX/2, to_string(ULLONG_MAX/2), 8) );
+}
+
+// base 16
+void
+test05()
+{
+ auto to_string = [](auto val) {
+ std::ostringstream ss;
+ ss << std::hex;
+ if (val < 0)
+ ss << '-' << (~val + 1ull);
+ else if (sizeof(val) == 1)
+ ss << (int)val;
+ else
+ ss << val;
+ return ss.str();
+ };
+
+ VERIFY( check_to_chars<char>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<signed char>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<unsigned char>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<signed short>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<unsigned short>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<signed int>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<unsigned int>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<signed long>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<unsigned long>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<signed long long>(123, to_string(123), 16) );
+ VERIFY( check_to_chars<unsigned long long>(123, to_string(123), 16) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-79, to_string(-79), 16) );
+ VERIFY( check_to_chars<signed char>(-79, to_string(-79), 16) );
+ VERIFY( check_to_chars<signed short>(-79, to_string(-79), 16) );
+ VERIFY( check_to_chars<signed int>(-79, to_string(-79), 16) );
+ VERIFY( check_to_chars<signed long>(-79, to_string(-79), 16) );
+ VERIFY( check_to_chars<signed long long>(-79, to_string(-79), 16) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX, to_string(CHAR_MAX), 16) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX, to_string(SCHAR_MAX), 16) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX, to_string(UCHAR_MAX), 16) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX, to_string(SHRT_MAX), 16) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX, to_string(USHRT_MAX), 16) );
+ VERIFY( check_to_chars<signed int>(INT_MAX, to_string(INT_MAX), 16) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX, to_string(UINT_MAX), 16) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX, to_string(LONG_MAX), 16) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX, to_string(ULONG_MAX), 16) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX, to_string(LLONG_MAX), 16) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX, to_string(ULLONG_MAX), 16) );
+
+ VERIFY( check_to_chars<char>(CHAR_MIN, to_string(CHAR_MIN), 16) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MIN, to_string(SCHAR_MIN), 16) );
+ VERIFY( check_to_chars<signed short>(SHRT_MIN, to_string(SHRT_MIN), 16) );
+ VERIFY( check_to_chars<signed int>(INT_MIN, to_string(INT_MIN), 16) );
+ VERIFY( check_to_chars<signed long>(LONG_MIN, to_string(LONG_MIN), 16) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MIN, to_string(LLONG_MIN), 16) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX/2, to_string(CHAR_MAX/2), 16) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX/2, to_string(SCHAR_MAX/2), 16) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX/2, to_string(UCHAR_MAX/2), 16) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX/2, to_string(SHRT_MAX/2), 16) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX/2, to_string(USHRT_MAX/2), 16) );
+ VERIFY( check_to_chars<signed int>(INT_MAX/2, to_string(INT_MAX/2), 16) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX/2, to_string(UINT_MAX/2), 16) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX/2, to_string(LONG_MAX/2), 16) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX/2, to_string(ULONG_MAX/2), 16) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX/2, to_string(LLONG_MAX/2), 16) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX/2, to_string(ULLONG_MAX/2), 16) );
+}
+
+#include <bitset>
+
+// base 2
+void
+test06()
+{
+ auto to_string = [](auto val) {
+ std::string s, sign;
+ if (val < 0)
+ {
+ auto absval = ~val + 1ull;
+ s = std::bitset<sizeof(absval) * CHAR_BIT>(absval).to_string();
+ sign = '-';
+ }
+ else
+ s = std::bitset<sizeof(val) * CHAR_BIT>(val).to_string();
+ auto pos = s.find_first_not_of("0");
+ if (pos == std::string::npos)
+ s.resize(1);
+ else
+ s.erase(0, pos);
+ return sign + s;
+ };
+
+ VERIFY( check_to_chars<char>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<signed char>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<unsigned char>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<signed short>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<unsigned short>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<signed int>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<unsigned int>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<signed long>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<unsigned long>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<signed long long>(123, to_string(123), 2) );
+ VERIFY( check_to_chars<unsigned long long>(123, to_string(123), 2) );
+
+ if constexpr (std::is_signed_v<char>)
+ VERIFY( check_to_chars<char>(-79, to_string(-79), 2) );
+ VERIFY( check_to_chars<signed char>(-79, to_string(-79), 2) );
+ VERIFY( check_to_chars<signed short>(-79, to_string(-79), 2) );
+ VERIFY( check_to_chars<signed int>(-79, to_string(-79), 2) );
+ VERIFY( check_to_chars<signed long>(-79, to_string(-79), 2) );
+ VERIFY( check_to_chars<signed long long>(-79, to_string(-79), 2) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX, to_string(CHAR_MAX), 2) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX, to_string(SCHAR_MAX), 2) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX, to_string(UCHAR_MAX), 2) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX, to_string(SHRT_MAX), 2) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX, to_string(USHRT_MAX), 2) );
+ VERIFY( check_to_chars<signed int>(INT_MAX, to_string(INT_MAX), 2) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX, to_string(UINT_MAX), 2) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX, to_string(LONG_MAX), 2) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX, to_string(ULONG_MAX), 2) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX, to_string(LLONG_MAX), 2) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX, to_string(ULLONG_MAX), 2) );
+
+ VERIFY( check_to_chars<char>(CHAR_MIN, to_string(CHAR_MIN), 2) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MIN, to_string(SCHAR_MIN), 2) );
+ VERIFY( check_to_chars<signed short>(SHRT_MIN, to_string(SHRT_MIN), 2) );
+ VERIFY( check_to_chars<signed int>(INT_MIN, to_string(INT_MIN), 2) );
+ VERIFY( check_to_chars<signed long>(LONG_MIN, to_string(LONG_MIN), 2) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MIN, to_string(LLONG_MIN), 2) );
+
+ VERIFY( check_to_chars<char>(CHAR_MAX/2, to_string(CHAR_MAX/2), 2) );
+ VERIFY( check_to_chars<signed char>(SCHAR_MAX/2, to_string(SCHAR_MAX/2), 2) );
+ VERIFY( check_to_chars<unsigned char>(UCHAR_MAX/2, to_string(UCHAR_MAX/2), 2) );
+ VERIFY( check_to_chars<signed short>(SHRT_MAX/2, to_string(SHRT_MAX/2), 2) );
+ VERIFY( check_to_chars<unsigned short>(USHRT_MAX/2, to_string(USHRT_MAX/2), 2) );
+ VERIFY( check_to_chars<signed int>(INT_MAX/2, to_string(INT_MAX/2), 2) );
+ VERIFY( check_to_chars<unsigned int>(UINT_MAX/2, to_string(UINT_MAX/2), 2) );
+ VERIFY( check_to_chars<signed long>(LONG_MAX/2, to_string(LONG_MAX/2), 2) );
+ VERIFY( check_to_chars<unsigned long>(ULONG_MAX/2, to_string(ULONG_MAX/2), 2) );
+ VERIFY( check_to_chars<signed long long>(LLONG_MAX/2, to_string(LLONG_MAX/2), 2) );
+ VERIFY( check_to_chars<unsigned long long>(ULLONG_MAX/2, to_string(ULLONG_MAX/2), 2) );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+ test05();
+ test06();
+}
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/1_neg.cc b/libstdc++-v3/testsuite/20_util/to_chars/1_neg.cc
new file mode 100644
index 00000000000..8302b250cd0
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/to_chars/1_neg.cc
@@ -0,0 +1,35 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <charconv>
+
+void
+test01(char* first, char* last)
+{
+#if _GLIBCXX_USE_WCHAR_T
+ std::to_chars(first, last, L'\x1'); // { dg-error "no matching" }
+ std::to_chars(first, last, L'\x1', 10); // { dg-error "no matching" }
+#endif
+
+ std::to_chars(first, last, u'\x1'); // { dg-error "no matching" }
+ std::to_chars(first, last, u'\x1', 10); // { dg-error "no matching" }
+ std::to_chars(first, last, U'\x1'); // { dg-error "no matching" }
+ std::to_chars(first, last, U'\x1', 10); // { dg-error "no matching" }
+}
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/2.cc b/libstdc++-v3/testsuite/20_util/to_chars/2.cc
new file mode 100644
index 00000000000..b28320cc7b8
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/to_chars/2.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do run { target c++17 } }
+
+#include <charconv>
+#include <testsuite_hooks.h>
+
+// Test std::to_chars error handling.
+
+void
+test01()
+{
+ char buf[9] = "********";
+ std::to_chars_result r;
+
+ r = std::to_chars(buf, buf, 1);
+ VERIFY( r.ec == std::errc::value_too_large );
+ VERIFY( r.ptr == buf );
+ VERIFY( *r.ptr == '*' );
+
+ r = std::to_chars(buf, buf + 3, 0b1000, 2);
+ VERIFY( r.ec == std::errc::value_too_large );
+ VERIFY( r.ptr == buf + 3 );
+ VERIFY( *r.ptr == '*' );
+ r = std::to_chars(buf, buf + 4, 0b1000, 2);
+ VERIFY( r.ec == std::errc{} );
+ VERIFY( r.ptr == buf + 4 );
+ VERIFY( *r.ptr == '*' );
+
+ r = std::to_chars(buf, buf + 4, 010000, 8);
+ VERIFY( r.ec == std::errc::value_too_large );
+ VERIFY( r.ptr == buf + 4 );
+ VERIFY( *r.ptr == '*' );
+ r = std::to_chars(buf, buf + 5, 010000, 8);
+ VERIFY( r.ec == std::errc{} );
+ VERIFY( r.ptr == buf + 5 );
+ VERIFY( *r.ptr == '*' );
+
+ r = std::to_chars(buf, buf + 5, 100000, 10);
+ VERIFY( r.ec == std::errc::value_too_large );
+ VERIFY( r.ptr == buf + 5 );
+ VERIFY( *r.ptr == '*' );
+ r = std::to_chars(buf, buf + 6, 100000, 10);
+ VERIFY( r.ec == std::errc{} );
+ VERIFY( r.ptr == buf + 6 );
+ VERIFY( *r.ptr == '*' );
+
+ r = std::to_chars(buf, buf + 6, 0x1000000, 16);
+ VERIFY( r.ec == std::errc::value_too_large );
+ VERIFY( r.ptr == buf + 6 );
+ VERIFY( *r.ptr == '*' );
+ r = std::to_chars(buf, buf + 7, 0x1000000, 16);
+ VERIFY( r.ec == std::errc{} );
+ VERIFY( r.ptr == buf + 7 );
+ VERIFY( *r.ptr == '*' );
+}
+
+int
+main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc b/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc
new file mode 100644
index 00000000000..d50588bd902
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/to_chars/requirements.cc
@@ -0,0 +1,49 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17" }
+// { dg-do compile { target c++17 } }
+
+#include <charconv>
+
+namespace std
+{
+ struct to_chars_result;
+
+ char* to_chars_result::*pm2 = &to_chars_result::ptr;
+ errc to_chars_result::*pm1 = &to_chars_result::ec;
+
+ to_chars_result (*f1)(char*, char*, char, int) = &to_chars;
+ to_chars_result (*f2)(char*, char*, signed char, int) = &to_chars;
+ to_chars_result (*f3)(char*, char*, unsigned char, int) = &to_chars;
+ to_chars_result (*f4)(char*, char*, signed short, int) = &to_chars;
+ to_chars_result (*f5)(char*, char*, unsigned short, int) = &to_chars;
+ to_chars_result (*f6)(char*, char*, signed int, int) = &to_chars;
+ to_chars_result (*f7)(char*, char*, unsigned int, int) = &to_chars;
+ to_chars_result (*f8)(char*, char*, signed long, int) = &to_chars;
+ to_chars_result (*f9)(char*, char*, unsigned long, int) = &to_chars;
+ to_chars_result (*f10)(char*, char*, signed long long, int) = &to_chars;
+ to_chars_result (*f11)(char*, char*, unsigned long long, int) = &to_chars;
+}
+
+void bind()
+{
+ char buf[1];
+ auto [p, e] = std::to_chars(buf, buf + 1, 1, 10);
+ char** pa = &p;
+ std::errc* ea = &e;
+}
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc
index 6f363efd24e..5a0581794de 100644
--- a/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/char/22131.cc
@@ -67,7 +67,7 @@ void test01()
fmt2.imbue(loc);
InIt ibeg2(fmt2);
err2 = ios_base::goodbit;
- mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
+ ibeg2 = mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
VERIFY( err2 == ios_base::failbit );
VERIFY( *ibeg2 == '#' );
VERIFY( val2 == "" );
diff --git a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc
index 3830cc366a7..0626e3c1660 100644
--- a/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc
+++ b/libstdc++-v3/testsuite/22_locale/money_get/get/wchar_t/22131.cc
@@ -67,7 +67,7 @@ void test01()
fmt2.imbue(loc);
InIt ibeg2(fmt2);
err2 = ios_base::goodbit;
- mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
+ ibeg2 = mg.get(ibeg2, iend2, intl, fmt2, err2, val2);
VERIFY( err2 == ios_base::failbit );
VERIFY( *ibeg2 == L'#' );
VERIFY( val2 == L"" );
diff --git a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/2.cc b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/2.cc
index b81f4d443a9..572ea9f23bc 100644
--- a/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/2.cc
+++ b/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator/2.cc
@@ -25,9 +25,7 @@
void test02(void)
{
-
typedef std::istreambuf_iterator<char> cistreambuf_iter;
- typedef cistreambuf_iter::streambuf_type cstreambuf_type;
const char slit01[] = "playa hermosa, liberia, guanacaste";
std::string str01(slit01);
std::istringstream istrs00(str01);
@@ -35,10 +33,14 @@ void test02(void)
// ctor sanity checks
cistreambuf_iter istrb_it01(istrs00);
- cistreambuf_iter istrb_it02;
- std::string tmp(istrb_it01, istrb_it02);
+ cistreambuf_iter istrb_eos;
+ VERIFY( istrb_it01 != istrb_eos );
+
+ std::string tmp(istrb_it01, istrb_eos);
VERIFY( tmp == str01 );
+ VERIFY( istrb_it01 == istrb_eos );
+
cistreambuf_iter istrb_it03(0);
cistreambuf_iter istrb_it04;
VERIFY( istrb_it03 == istrb_it04 );
diff --git a/libstdc++-v3/testsuite/26_numerics/complex/c99.cc b/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
index 70189627ca2..9b0def408c8 100644
--- a/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
+++ b/libstdc++-v3/testsuite/26_numerics/complex/c99.cc
@@ -26,7 +26,8 @@
int main()
{
-#if _GLIBCXX_HAVE_COMPLEX_H
+#if _GLIBCXX_HAVE_COMPLEX_H && !defined(__STRICT_ANSI__)
+ // This is a GNU extension.
double _Complex x = .5;
double _Complex y = cacos (x);
(void)y;
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h
new file mode 100644
index 00000000000..22d84b2f14e
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++11.h
@@ -0,0 +1,33 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=c++11" }
+
+#include <complex.h>
+
+// Should be equivalent to #include <complex>
+template class std::complex<double>;
+
+#ifdef complex
+# error "'complex' is defined as a macro by <complex.h> for -std=c++11"
+#endif
+#ifdef imaginary
+# error "'imaginary' is defined as a macro by <complex.h> for -std=c++11"
+#endif
+#ifdef I
+# error "'I' is defined as a macro by <complex.h> for -std=c++11"
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h
new file mode 100644
index 00000000000..62674466c3d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_c++98.h
@@ -0,0 +1,55 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=c++98" }
+
+#include <complex.h>
+
+// Should be equivalent to C99 <complex>, not C++ <complex>
+namespace std
+{
+ struct complex;
+}
+
+#if _GLIBCXX_HAVE_COMPLEX_H
+namespace test
+{
+ using ::cacos;
+ using ::casin;
+ using ::catan;
+ using ::ccos;
+ using ::csin;
+ using ::ctan;
+ using ::ccosh;
+ using ::csinh;
+ using ::ctanh;
+ using ::cexp;
+ using ::clog;
+ using ::cabs;
+ using ::cpow;
+ using ::csqrt;
+ using ::carg;
+ using ::cimag;
+ using ::conj;
+ using ::cproj;
+ using ::creal;
+}
+#endif
+
+#ifndef complex
+# error "'complex' is not defined as a macro by <complex.h> for -std=c++98"
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_gnu++11.h b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_gnu++11.h
new file mode 100644
index 00000000000..9110ae4ecb2
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/headers/complex.h/std_gnu++11.h
@@ -0,0 +1,52 @@
+// Copyright (C) 2017 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+
+#include <complex.h>
+
+// Should be equivalent to #include <complex>
+template class std::complex<double>;
+
+#if _GLIBCXX_HAVE_COMPLEX_H
+namespace test
+{
+ using ::cacos;
+ using ::casin;
+ using ::catan;
+ using ::ccos;
+ using ::csin;
+ using ::ctan;
+ using ::ccosh;
+ using ::csinh;
+ using ::ctanh;
+ using ::cexp;
+ using ::clog;
+ using ::cabs;
+ using ::cpow;
+ using ::csqrt;
+ using ::carg;
+ using ::cimag;
+ using ::conj;
+ using ::cproj;
+ using ::creal;
+}
+#endif
+
+#ifdef complex
+# error "'complex' is defined as a macro by <complex.h> for -std=gnu++11"
+#endif