From patchwork Wed Sep 18 19:38:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Pluzhnikov X-Patchwork-Id: 275787 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0EEC92C00B7 for ; Thu, 19 Sep 2013 05:39:10 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; q=dns; s=default; b=ZmrVr3gPOxux6CP Emm5m7jWmHkgM8jOpDgal4VoQJzhv8Qttt6kXLxqZOy5I2LFoFs9YZYJJ9GpG8Fg KCy0+3sjLTf0SU22UscP9muQEvXh+HICMAvbULimUiKolRGZ+B7FmjAbspv9Z2VK HIb1hIPd+eA9h0wxKwfIGzDnKypM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; s=default; bh=ca/KcgBDGM6e/PZ8PhvJy BKfoIA=; b=dwXBMdN2yzbniutpMNntPJGWbSi4DEm8jlinKvE8R/GsnsANfjCqr dgGxGOx/ZOm7eruVhZx0utEAW1fov6ByQD5NKmFAeiNhVL0SI3AClBWj95EvD0D1 hS0VQLGorsQxv9OvVckWmBxp8kXaMNLLLVmVSTeT77uGqWEiTsHZjw= Received: (qmail 24803 invoked by alias); 18 Sep 2013 19:39:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 24781 invoked by uid 89); 18 Sep 2013 19:39:03 -0000 Received: from mail-ie0-f169.google.com (HELO mail-ie0-f169.google.com) (209.85.223.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 18 Sep 2013 19:39:03 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_50, KHOP_THREADED, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f169.google.com Received: by mail-ie0-f169.google.com with SMTP id tp5so14056546ieb.28 for ; Wed, 18 Sep 2013 12:38:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=99zwszb84sI1tm1uzT2Hpahwb47H/fGg2x3Xbpk15dM=; b=RmiZ5VgEP27foBgrjulmlOnwItOs5PzOQ+WvvXIMeG3hoxUOmDsVlOm7So/TxvgZmV nHmiEBZAKLDCjj+QJ/Ax6X5XQkVr3mUvSi+0hjLE0F+P5quKjGS+/8wp1WlqggedhKWZ jjdelpmkkW5GnJt/ZsWPXwww3wSCSv8ucWKcUpmRqFNMIisNLWS04pNX/baOzGpdYzko mS6gTo3DpGCHOVM0HQjLRdHkGYldXjJ3F+UFPofUFM5QRr9K6TkCJNGCF5u7yh7WHzV3 lbvYFOADcOcahGrBPdKvyo+lpg6PmHoqUCyL1bgj/gB/Gs65AZ1Ttf2bLunJFdOqYes7 ntUQ== X-Gm-Message-State: ALoCoQn/eS+1bL9ydgp5owZuC/XDscLOqeaFPz3ip6FS/dRfr9j7VHbkZLU5fa7NLvVP8CH/JgzGwM8tAqaomTujWxNou4zfRpJi9RYNm56TBI+faExDFxnNwLPruF4L2W+Es5v8fZu1zDs/V+KdnpHhayfzJjvEQEJutqY1tqOPUsjiUb5qZ/HGKRKVFz+U8l3EeRKeLOJ27LCX/rzKGaACXWokMT0y6g== X-Received: by 10.43.147.193 with SMTP id kd1mr4589002icc.17.1379533139539; Wed, 18 Sep 2013 12:38:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.63.67 with HTTP; Wed, 18 Sep 2013 12:38:29 -0700 (PDT) In-Reply-To: <5232E2AF.4000106@oracle.com> References: <5232E2AF.4000106@oracle.com> From: Paul Pluzhnikov Date: Wed, 18 Sep 2013 12:38:29 -0700 Message-ID: Subject: Re: [patch] Make vector::at() assertion message more useful (try #2) To: Paolo Carlini Cc: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= , gcc-patches List , "libstdc++" On Fri, Sep 13, 2013 at 3:02 AM, Paolo Carlini wrote: > - The game with the variadic and the non-variadic __throw_out_of_range makes > me a little nervous. Let's just name the new one differently, like > __throw_out_of_range_var. Replaced with __throw_out_of_range_fmt. > - Please consistently use __builtin_alloca everywhere, alloca isn't a > standard function. Done. > - I would rather call the file itself snprintf_lite.cc, in order not to fool > somebody that it actually implements the whole snprintf. Done. > - I'm a bit confused about __concat_size_t returning -1. Since it only > formats integers, I think we can be *sure* that the buffer is big enough. How so? The caller could do this: __snprintf_lite("aaa: %zu, 8, 12345678); By the time we get to __concat_size_t, we only have 3 characters left. > Then, if it returns -1 something is going *very badly* wrong, shouldn't we > __builtin_abort() or something similar? I've re-worked this part -- if this ever happens, throw a logic_error with a message to file a bug. > - In terms of buffer sizes, this comment: > > // enough for expanding up to 5 size_t's in the format. > > and then the actual code in __snprintf_lite makes me a little nervous. > Agreed, we are not going to overflow the buffer, but truncating with no > diagnostic whatsoever seems rather gross. We can probably sort out this > later, new ideas welcome, anyway. Re-worked. > - While we are at it, shouldn't we use the new facility at least in array, > vector and deque too? For consistency over the containers. Done. I also expanded snprintf_lite to handle '%s', as that comes handy inside string _M_check. Thanks, P.S. In the process of updating callers of __throw_out_of_range, I've discovered that two of them had already used __builtin_sprintf. P.P.S. Sorry this patch grew ... I can split it into parts if that's easier to review. Index: libstdc++-v3/include/bits/functexcept.h =================================================================== --- libstdc++-v3/include/bits/functexcept.h (revision 202709) +++ libstdc++-v3/include/bits/functexcept.h (working copy) @@ -75,6 +75,10 @@ __throw_out_of_range(const char*) __attribute__((__noreturn__)); void + __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__)) + __attribute__((__format__(__printf__, 1, 2))); + + void __throw_runtime_error(const char*) __attribute__((__noreturn__)); void Index: libstdc++-v3/src/c++11/functexcept.cc =================================================================== --- libstdc++-v3/src/c++11/functexcept.cc (revision 202709) +++ libstdc++-v3/src/c++11/functexcept.cc (working copy) @@ -31,6 +31,7 @@ #include #include #include +#include #ifdef _GLIBCXX_USE_NLS # include @@ -39,6 +40,12 @@ # define _(msgid) (msgid) #endif +namespace __gnu_cxx +{ + int __snprintf_lite(char *__buf, size_t __bufsize, const char *__fmt, + va_list __ap); +} + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -80,6 +87,22 @@ { _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s))); } void + __throw_out_of_range_fmt(const char* __fmt, ...) + { + const size_t __len = __builtin_strlen(__fmt); + // We expect at most 2 numbers, and 1 short string. The additional + // 512 bytes should provide more than enough space for expansion. + const size_t __alloca_size = __len + 512; + char *const __s = static_cast(__builtin_alloca(__alloca_size)); + va_list __ap; + + va_start(__ap, __fmt); + __gnu_cxx::__snprintf_lite(__s, __alloca_size, __fmt, __ap); + _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s))); + va_end(__ap); // Not reached. + } + + void __throw_runtime_error(const char* __s __attribute__((unused))) { _GLIBCXX_THROW_OR_ABORT(runtime_error(_(__s))); } Index: libstdc++-v3/src/c++11/snprintf_lite.cc =================================================================== --- libstdc++-v3/src/c++11/snprintf_lite.cc (revision 0) +++ libstdc++-v3/src/c++11/snprintf_lite.cc (revision 0) @@ -0,0 +1,152 @@ +// Debugging support -*- C++ -*- + +// Copyright (C) 2013 Free Software Foundation, Inc. +// +// This file is part of GCC. +// +// GCC 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. +// +// GCC 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 +// . + +#include +#include +#include + +namespace std { + template + int + __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit, + ios_base::fmtflags __flags, bool __dec); +} + +namespace __gnu_cxx { + + // Private helper to throw logic error if snprintf_lite runs out + // of space (which is not expected to ever happen). + // NUL-terminates __buf. + void + __throw_insufficient_space(const char *__buf, const char *__bufend) + __attribute__((__noreturn__)); + + void + __throw_insufficient_space(const char *__buf, const char *__bufend) + { + // Include space for trailing NUL. + const size_t __len = __bufend - __buf + 1; + + const char __err[] = "not enough space for format expansion " + "(Please submit full bug report at http://gcc.gnu.org/bugs.html):\n "; + const size_t __errlen = sizeof(__err) - 1; + + char *const __e + = static_cast(__builtin_alloca(__errlen + __len)); + + __builtin_memcpy(__e, __err, __errlen); + __builtin_memcpy(__e + __errlen, __buf, __len - 1); + __e[__errlen + __len - 1] = '\0'; + std::__throw_logic_error(__e); + } + + + // Private routine to append decimal representation of VAL to the given + // BUFFER, but not more than BUFSIZE characters. + // Does not NUL-terminate the output buffer. + // Returns number of characters appended, or -1 if BUFSIZE is too small. + int __concat_size_t(char *__buf, size_t __bufsize, size_t __val) + { + // Long enough for decimal representation. + int __ilen = 3 * sizeof(__val); + char *__cs = static_cast(__builtin_alloca(__ilen)); + size_t __len = std::__int_to_char(__cs + __ilen, __val, + std::__num_base::_S_atoms_out, + std::ios_base::dec, true); + if (__bufsize < __len) + return -1; + + __builtin_memcpy(__buf, __cs + __ilen - __len, __len); + return __len; + } + + + // Private routine to print into __buf arguments according to format, + // not to exceed __bufsize. + // Only '%%', '%s' and '%zu' format specifiers are understood. + // Returns number of characters printed (excluding terminating NUL). + // Always NUL-terminates __buf. + // Throws logic_error on insufficient space. + int __snprintf_lite(char *__buf, size_t __bufsize, const char *__fmt, + va_list __ap) + { + char *__d = __buf; + const char *__s = __fmt; + const char *const __limit = __d + __bufsize - 1; // Leave space for NUL. + + while (__s[0] != '\0' && __d < __limit) + { + if (__s[0] == '%') + switch (__s[1]) + { + default: // Stray '%'. Just print it. + break; + case '%': // '%%' + __s += 1; + break; + case 's': // '%s'. + { + const char *__v = va_arg(__ap, const char *); + + while (__v[0] != '\0' && __d < __limit) + *__d++ = *__v++; + + if (__v[0] != '\0') + // Not enough space for __fmt expansion. + __throw_insufficient_space(__buf, __d); + + __s += 2; // Step over %s. + continue; + } + break; + case 'z': + if (__s[2] == 'u') // '%zu' -- expand next size_t arg. + { + const int __len = __concat_size_t(__d, __limit - __d, + va_arg(__ap, size_t)); + if (__len > 0) + __d += __len; + else + // Not enough space for __fmt expansion. + __throw_insufficient_space(__buf, __d); + + __s += 3; // Step over %zu + continue; + } + // Stray '%zX'. Just print it. + break; + } + *__d++ = *__s++; + } + + if (__s[0] != '\0') + // Not enough space for __fmt expansion. + __throw_insufficient_space(__buf, __d); + + *__d = '\0'; + return __d - __buf; + } + +} // __gnu_cxx Index: libstdc++-v3/src/c++11/Makefile.am =================================================================== --- libstdc++-v3/src/c++11/Makefile.am (revision 202709) +++ libstdc++-v3/src/c++11/Makefile.am (working copy) @@ -42,6 +42,7 @@ random.cc \ regex.cc \ shared_ptr.cc \ + snprintf_lite.cc \ system_error.cc \ thread.cc Index: libstdc++-v3/src/c++11/Makefile.in =================================================================== --- libstdc++-v3/src/c++11/Makefile.in (revision 202709) +++ libstdc++-v3/src/c++11/Makefile.in (working copy) @@ -70,7 +70,8 @@ am__objects_1 = chrono.lo condition_variable.lo debug.lo \ functexcept.lo functional.lo future.lo hash_c++0x.lo \ hashtable_c++0x.lo limits.lo mutex.lo placeholders.lo \ - random.lo regex.lo shared_ptr.lo system_error.lo thread.lo + random.lo regex.lo shared_ptr.lo snprintf_lite.lo \ + system_error.lo thread.lo @ENABLE_EXTERN_TEMPLATE_TRUE@am__objects_2 = fstream-inst.lo \ @ENABLE_EXTERN_TEMPLATE_TRUE@ string-inst.lo wstring-inst.lo am_libc__11convenience_la_OBJECTS = $(am__objects_1) $(am__objects_2) @@ -324,6 +325,7 @@ random.cc \ regex.cc \ shared_ptr.cc \ + snprintf_lite.cc \ system_error.cc \ thread.cc Index: libstdc++-v3/config/abi/pre/gnu.ver =================================================================== --- libstdc++-v3/config/abi/pre/gnu.ver (revision 202709) +++ libstdc++-v3/config/abi/pre/gnu.ver (working copy) @@ -1365,6 +1365,9 @@ # std::get_unexpected() _ZSt14get_unexpectedv; + # std::__throw_out_of_range_fmt(char const*, ...) + _ZSt24__throw_out_of_range_fmtPKcz; + } GLIBCXX_3.4.19; # Symbols in the support library (libsupc++) have their own tag. Index: libstdc++-v3/include/std/array =================================================================== --- libstdc++-v3/include/std/array (revision 202709) +++ libstdc++-v3/include/std/array (working copy) @@ -180,7 +180,9 @@ at(size_type __n) { if (__n >= _Nm) - std::__throw_out_of_range(__N("array::at")); + std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) " + ">= _Nm (which is %zu)"), + __n, _Nm); return _AT_Type::_S_ref(_M_elems, __n); } @@ -190,7 +192,9 @@ // Result of conditional expression must be an lvalue so use // boolean ? lvalue : (throw-expr, lvalue) return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) - : (std::__throw_out_of_range(__N("array::at")), + : (std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) " + ">= _Nm (which is %zu)"), + __n, _Nm), _AT_Type::_S_ref(_M_elems, 0)); } Index: libstdc++-v3/include/debug/array =================================================================== --- libstdc++-v3/include/debug/array (revision 202709) +++ libstdc++-v3/include/debug/array (working copy) @@ -165,7 +165,10 @@ at(size_type __n) { if (__n >= _Nm) - std::__throw_out_of_range(__N("array::at")); + std::__throw_out_of_range_fmt(__N("array::at: __n " + "(which is %zu) >= _Nm " + "(which is %zu)"), + __n, _Nm); return _AT_Type::_S_ref(_M_elems, __n); } @@ -175,7 +178,9 @@ // Result of conditional expression must be an lvalue so use // boolean ? lvalue : (throw-expr, lvalue) return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) - : (std::__throw_out_of_range(__N("array::at")), + : (std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) " + ">= _Nm (which is %zu)"), + __n, _Nm), _AT_Type::_S_ref(_M_elems, 0)); } Index: libstdc++-v3/include/profile/array =================================================================== --- libstdc++-v3/include/profile/array (revision 202709) +++ libstdc++-v3/include/profile/array (working copy) @@ -138,7 +138,10 @@ at(size_type __n) { if (__n >= _Nm) - std::__throw_out_of_range(__N("array::at")); + std::__throw_out_of_range_fmt(__N("array::at: __n " + "(which is %zu) >= _Nm " + "(which is %zu)"), + __n, _Nm); return _AT_Type::_S_ref(_M_elems, __n); } @@ -148,7 +151,9 @@ // Result of conditional expression must be an lvalue so use // boolean ? lvalue : (throw-expr, lvalue) return __n < _Nm ? _AT_Type::_S_ref(_M_elems, __n) - : (std::__throw_out_of_range(__N("array::at")), + : (std::__throw_out_of_range_fmt(__N("array::at: __n (which is %zu) " + ">= _Nm (which is %zu)"), + __n, _Nm), _AT_Type::_S_ref(_M_elems, 0)); } Index: libstdc++-v3/include/std/bitset =================================================================== --- libstdc++-v3/include/std/bitset (revision 202709) +++ libstdc++-v3/include/std/bitset (working copy) @@ -752,7 +752,27 @@ typedef _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)> _Base; typedef unsigned long _WordT; + template void + _M_check_initial_position(const std::basic_string<_CharT, _Traits, _Alloc>& __s, + size_t __position) const + { + if (__position > __s.size()) + __throw_out_of_range_fmt(__N("bitset::bitset: __position " + "(which is %zu) > __s.size() " + "(which is %zu)"), + __position, __s.size()); + } + + void _M_check(size_t __position, const char *__s) const + { + if (__position >= _Nb) + __throw_out_of_range_fmt(__N("%s: __position (which is %zu) " + ">= _Nb (which is %zu)"), + __s, __position, _Nb); + } + + void _M_do_sanitize() _GLIBCXX_NOEXCEPT { typedef _Sanitize<_Nb % _GLIBCXX_BITSET_BITS_PER_WORD> __sanitize_type; @@ -867,9 +887,7 @@ size_t __position = 0) : _Base() { - if (__position > __s.size()) - __throw_out_of_range(__N("bitset::bitset initial position " - "not valid")); + _M_check_initial_position(__s, __position); _M_copy_from_string(__s, __position, std::basic_string<_CharT, _Traits, _Alloc>::npos, _CharT('0'), _CharT('1')); @@ -890,9 +908,7 @@ size_t __position, size_t __n) : _Base() { - if (__position > __s.size()) - __throw_out_of_range(__N("bitset::bitset initial position " - "not valid")); + _M_check_initial_position(__s, __position); _M_copy_from_string(__s, __position, __n, _CharT('0'), _CharT('1')); } @@ -904,9 +920,7 @@ _CharT __zero, _CharT __one = _CharT('1')) : _Base() { - if (__position > __s.size()) - __throw_out_of_range(__N("bitset::bitset initial position " - "not valid")); + _M_check_initial_position(__s, __position); _M_copy_from_string(__s, __position, __n, __zero, __one); } @@ -1067,8 +1081,7 @@ bitset<_Nb>& set(size_t __position, bool __val = true) { - if (__position >= _Nb) - __throw_out_of_range(__N("bitset::set")); + this->_M_check(__position, __N("bitset::set")); return _Unchecked_set(__position, __val); } @@ -1092,8 +1105,7 @@ bitset<_Nb>& reset(size_t __position) { - if (__position >= _Nb) - __throw_out_of_range(__N("bitset::reset")); + this->_M_check(__position, __N("bitset::reset")); return _Unchecked_reset(__position); } @@ -1116,8 +1128,7 @@ bitset<_Nb>& flip(size_t __position) { - if (__position >= _Nb) - __throw_out_of_range(__N("bitset::flip")); + this->_M_check(__position, __N("bitset::flip")); return _Unchecked_flip(__position); } @@ -1302,8 +1313,7 @@ bool test(size_t __position) const { - if (__position >= _Nb) - __throw_out_of_range(__N("bitset::test")); + this->_M_check(__position, __N("bitset::test")); return _Unchecked_test(__position); } Index: libstdc++-v3/include/ext/vstring.h =================================================================== --- libstdc++-v3/include/ext/vstring.h (revision 202709) +++ libstdc++-v3/include/ext/vstring.h (working copy) @@ -85,7 +85,9 @@ _M_check(size_type __pos, const char* __s) const { if (__pos > this->size()) - std::__throw_out_of_range(__N(__s)); + std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " + "this->size() (which is %zu)"), + __s, __pos, this->size()); return __pos; } @@ -581,7 +583,10 @@ at(size_type __n) const { if (__n >= this->size()) - std::__throw_out_of_range(__N("__versa_string::at")); + std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); return this->_M_data()[__n]; } @@ -600,7 +605,10 @@ at(size_type __n) { if (__n >= this->size()) - std::__throw_out_of_range(__N("__versa_string::at")); + std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); this->_M_leak(); return this->_M_data()[__n]; } Index: libstdc++-v3/include/bits/stl_deque.h =================================================================== --- libstdc++-v3/include/bits/stl_deque.h (revision 202709) +++ libstdc++-v3/include/bits/stl_deque.h (working copy) @@ -1269,7 +1269,10 @@ _M_range_check(size_type __n) const { if (__n >= this->size()) - __throw_out_of_range(__N("deque::_M_range_check")); + __throw_out_of_range_fmt(__N("deque::_M_range_check: __n " + "(which is %zu)>= this->size() " + "(which is %zu)"), + __n, this->size()); } public: Index: libstdc++-v3/include/bits/stl_bvector.h =================================================================== --- libstdc++-v3/include/bits/stl_bvector.h (revision 202709) +++ libstdc++-v3/include/bits/stl_bvector.h (working copy) @@ -785,7 +785,10 @@ _M_range_check(size_type __n) const { if (__n >= this->size()) - __throw_out_of_range(__N("vector::_M_range_check")); + __throw_out_of_range_fmt(__N("vector::_M_range_check: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); } public: Index: libstdc++-v3/include/bits/basic_string.h =================================================================== --- libstdc++-v3/include/bits/basic_string.h (revision 202709) +++ libstdc++-v3/include/bits/basic_string.h (working copy) @@ -321,7 +321,9 @@ _M_check(size_type __pos, const char* __s) const { if (__pos > this->size()) - __throw_out_of_range(__N(__s)); + __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " + "this->size() (which is %zu)"), + __s, __pos, this->size()); return __pos; } @@ -865,7 +867,10 @@ at(size_type __n) const { if (__n >= this->size()) - __throw_out_of_range(__N("basic_string::at")); + __throw_out_of_range_fmt(__N("basic_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); return _M_data()[__n]; } @@ -884,7 +889,10 @@ at(size_type __n) { if (__n >= size()) - __throw_out_of_range(__N("basic_string::at")); + __throw_out_of_range_fmt(__N("basic_string::at: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); _M_leak(); return _M_data()[__n]; } Index: libstdc++-v3/include/bits/stl_vector.h =================================================================== --- libstdc++-v3/include/bits/stl_vector.h (revision 202709) +++ libstdc++-v3/include/bits/stl_vector.h (working copy) @@ -785,7 +785,10 @@ _M_range_check(size_type __n) const { if (__n >= this->size()) - __throw_out_of_range(__N("vector::_M_range_check")); + __throw_out_of_range_fmt(__N("vector::_M_range_check: __n " + "(which is %zu) >= this->size() " + "(which is %zu)"), + __n, this->size()); } public: Index: libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/assign_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1302 } +// { dg-error "no matching" "" { target *-*-* } 1305 } #include Index: libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/insert_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1343 } +// { dg-error "no matching" "" { target *-*-* } 1346 } #include Index: libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_1_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1228 } +// { dg-error "no matching" "" { target *-*-* } 1231 } #include Index: libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/vector/requirements/dr438/constructor_2_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1228 } +// { dg-error "no matching" "" { target *-*-* } 1231 } #include #include Index: libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/assign_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1760 } +// { dg-error "no matching" "" { target *-*-* } 1763 } #include Index: libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/insert_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1844 } +// { dg-error "no matching" "" { target *-*-* } 1847 } #include @@ -32,4 +32,3 @@ std::deque d; d.insert(d.begin(), 10, 1); } - Index: libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1693 } +// { dg-error "no matching" "" { target *-*-* } 1696 } #include Index: libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc (working copy) @@ -18,7 +18,7 @@ // . // { dg-do compile } -// { dg-error "no matching" "" { target *-*-* } 1693 } +// { dg-error "no matching" "" { target *-*-* } 1696 } #include #include Index: libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc (working copy) @@ -28,6 +28,6 @@ int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 270 } -// { dg-error "static assertion failed" "" { target *-*-* } 279 } -// { dg-error "static assertion failed" "" { target *-*-* } 287 } +// { dg-error "static assertion failed" "" { target *-*-* } 274 } +// { dg-error "static assertion failed" "" { target *-*-* } 283 } +// { dg-error "static assertion failed" "" { target *-*-* } 291 } Index: libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc =================================================================== --- libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (revision 202709) +++ libstdc++-v3/testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc (working copy) @@ -23,4 +23,4 @@ typedef std::tuple_element<1, std::array>::type type; -// { dg-error "static assertion failed" "" { target *-*-* } 316 } +// { dg-error "static assertion failed" "" { target *-*-* } 320 } Index: libstdc++-v3/testsuite/util/exception/safety.h =================================================================== --- libstdc++-v3/testsuite/util/exception/safety.h (revision 202709) +++ libstdc++-v3/testsuite/util/exception/safety.h (working copy) @@ -47,22 +47,12 @@ const typename distribution_type::param_type p(0, __max_size); size_type random = generator(p); if (random < distribution.min() || random > distribution.max()) - { - std::string __s("setup_base::generate"); - __s += "\n"; - __s += "random number generated is: "; - char buf[40]; - __builtin_sprintf(buf, "%lu", (unsigned long)random); - __s += buf; - __s += " on range ["; - __builtin_sprintf(buf, "%lu", (unsigned long)distribution.min()); - __s += buf; - __s += ", "; - __builtin_sprintf(buf, "%lu", (unsigned long)distribution.max()); - __s += buf; - __s += "]\n"; - std::__throw_out_of_range(__s.c_str()); - } + std::__throw_out_of_range_fmt(__N("setup_base::generate\n" + "random number generated is: %zu " + "out of range [%zu, %zu]\n"), + (size_t)random, + (size_t)distribution.min(), + (size_t)distribution.max()); return random; }