mirror of git://gcc.gnu.org/git/gcc.git
functions.h (__gnu_debug::__check_string): Move...
2018-07-06 François Dumont <fdumont@gcc.gnu.org> * include/debug/functions.h (__gnu_debug::__check_string): Move... * include/debug/string (__gnu_debug::__check_string): ... here. (_GLIBCXX_DEBUG_VERIFY_STR_COND_AT): New. (__glibcxx_check_string_n_constructor): New. (__gnu_debug::basic_string<>(const _CharT*, size_type, const _Alloc&)): Use latter. (__glibcxx_check_string_constructor): New. (__gnu_debug::basic_string<>(const _CharT*, const _Alloc&)): Use latter. * testsuite/21_strings/basic_string/debug/1_neg.cc: New. * testsuite/21_strings/basic_string/debug/2_neg.cc: New. From-SVN: r262480
This commit is contained in:
parent
582d1f9049
commit
1e736a9531
|
|
@ -1,3 +1,17 @@
|
|||
2018-07-06 François Dumont <fdumont@gcc.gnu.org>
|
||||
|
||||
* include/debug/functions.h (__gnu_debug::__check_string): Move...
|
||||
* include/debug/string (__gnu_debug::__check_string): ... here.
|
||||
(_GLIBCXX_DEBUG_VERIFY_STR_COND_AT): New.
|
||||
(__glibcxx_check_string_n_constructor): New.
|
||||
(__gnu_debug::basic_string<>(const _CharT*, size_type, const _Alloc&)):
|
||||
Use latter.
|
||||
(__glibcxx_check_string_constructor): New.
|
||||
(__gnu_debug::basic_string<>(const _CharT*, const _Alloc&)):
|
||||
Use latter.
|
||||
* testsuite/21_strings/basic_string/debug/1_neg.cc: New.
|
||||
* testsuite/21_strings/basic_string/debug/2_neg.cc: New.
|
||||
|
||||
2018-07-06 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/84928 use std::move in <numeric> algorithms
|
||||
|
|
|
|||
|
|
@ -211,29 +211,6 @@ namespace __gnu_debug
|
|||
return __foreign_iterator_aux(__it, __other, __other_end, _Integral());
|
||||
}
|
||||
|
||||
/** Checks that __s is non-NULL or __n == 0, and then returns __s. */
|
||||
template<typename _CharT, typename _Integer>
|
||||
inline const _CharT*
|
||||
__check_string(const _CharT* __s,
|
||||
const _Integer& __n __attribute__((__unused__)))
|
||||
{
|
||||
#ifdef _GLIBCXX_DEBUG_PEDANTIC
|
||||
__glibcxx_assert(__s != 0 || __n == 0);
|
||||
#endif
|
||||
return __s;
|
||||
}
|
||||
|
||||
/** Checks that __s is non-NULL and then returns __s. */
|
||||
template<typename _CharT>
|
||||
inline const _CharT*
|
||||
__check_string(const _CharT* __s)
|
||||
{
|
||||
#ifdef _GLIBCXX_DEBUG_PEDANTIC
|
||||
__glibcxx_assert(__s != 0);
|
||||
#endif
|
||||
return __s;
|
||||
}
|
||||
|
||||
// Can't check if an input iterator sequence is sorted, because we
|
||||
// can't step through the sequence.
|
||||
template<typename _InputIterator>
|
||||
|
|
|
|||
|
|
@ -36,10 +36,52 @@
|
|||
#include <debug/safe_container.h>
|
||||
#include <debug/safe_iterator.h>
|
||||
|
||||
#define _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_Cond,_File,_Line,_Func) \
|
||||
if (! (_Cond)) \
|
||||
__gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
|
||||
._M_message(#_Cond)._M_error()
|
||||
|
||||
namespace __gnu_debug
|
||||
{
|
||||
/// Class std::basic_string with safety/checking/debug instrumentation.
|
||||
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
|
||||
/** Checks that __s is non-NULL or __n == 0, and then returns __s. */
|
||||
template<typename _CharT, typename _Integer>
|
||||
inline const _CharT*
|
||||
__check_string(const _CharT* __s,
|
||||
_Integer __n __attribute__((__unused__)),
|
||||
const char* __file __attribute__((__unused__)),
|
||||
unsigned int __line __attribute__((__unused__)),
|
||||
const char* __function __attribute__((__unused__)))
|
||||
{
|
||||
#ifdef _GLIBCXX_DEBUG_PEDANTIC
|
||||
_GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0,
|
||||
__file, __line, __function);
|
||||
#endif
|
||||
return __s;
|
||||
}
|
||||
|
||||
/** Checks that __s is non-NULL and then returns __s. */
|
||||
template<typename _CharT>
|
||||
inline const _CharT*
|
||||
__check_string(const _CharT* __s,
|
||||
const char* __file __attribute__((__unused__)),
|
||||
unsigned int __line __attribute__((__unused__)),
|
||||
const char* __function __attribute__((__unused__)))
|
||||
{
|
||||
#ifdef _GLIBCXX_DEBUG_PEDANTIC
|
||||
_GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0,
|
||||
__file, __line, __function);
|
||||
#endif
|
||||
return __s;
|
||||
}
|
||||
|
||||
#define __glibcxx_check_string_n_constructor(_Str, _Size) \
|
||||
__check_string(_Str, _Size, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||
|
||||
#define __glibcxx_check_string_constructor(_Str) \
|
||||
__check_string(_Str, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
||||
|
||||
/// Class std::basic_string with safety/checking/debug instrumentation.
|
||||
template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
|
||||
typename _Allocator = std::allocator<_CharT> >
|
||||
class basic_string
|
||||
: public __gnu_debug::_Safe_container<
|
||||
|
|
@ -125,10 +167,10 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
|
|||
|
||||
basic_string(const _CharT* __s, size_type __n,
|
||||
const _Allocator& __a = _Allocator())
|
||||
: _Base(__gnu_debug::__check_string(__s, __n), __n, __a) { }
|
||||
: _Base(__glibcxx_check_string_n_constructor(__s, __n), __n, __a) { }
|
||||
|
||||
basic_string(const _CharT* __s, const _Allocator& __a = _Allocator())
|
||||
: _Base(__gnu_debug::__check_string(__s), __a)
|
||||
: _Base(__glibcxx_check_string_constructor(__s), __a)
|
||||
{ this->assign(__s); }
|
||||
|
||||
basic_string(size_type __n, _CharT __c,
|
||||
|
|
@ -563,7 +605,8 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
|
|||
|
||||
template<typename _InputIterator>
|
||||
iterator
|
||||
insert(const_iterator __p, _InputIterator __first, _InputIterator __last)
|
||||
insert(const_iterator __p,
|
||||
_InputIterator __first, _InputIterator __last)
|
||||
{
|
||||
typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
|
||||
__glibcxx_check_insert_range(__p, __first, __last, __dist);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2018 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-do run { xfail *-*-* } }
|
||||
|
||||
#define _GLIBCXX_DEBUG_PEDANTIC
|
||||
|
||||
#include <debug/string>
|
||||
|
||||
void test01()
|
||||
{
|
||||
const char* __null_str = 0;
|
||||
__gnu_debug::string str(__null_str, 1);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2018 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-do run { xfail *-*-* } }
|
||||
|
||||
#define _GLIBCXX_DEBUG_PEDANTIC
|
||||
|
||||
#include <debug/string>
|
||||
|
||||
void test01()
|
||||
{
|
||||
const char* __null_str = 0;
|
||||
__gnu_debug::string str(__null_str);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue