From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libstdc++-v3/testsuite/util/debug/checks.h | 379 +++++++++++++++++++++++++++++ 1 file changed, 379 insertions(+) create mode 100644 libstdc++-v3/testsuite/util/debug/checks.h (limited to 'libstdc++-v3/testsuite/util/debug') diff --git a/libstdc++-v3/testsuite/util/debug/checks.h b/libstdc++-v3/testsuite/util/debug/checks.h new file mode 100644 index 000000000..b42ef1a44 --- /dev/null +++ b/libstdc++-v3/testsuite/util/debug/checks.h @@ -0,0 +1,379 @@ +// Copyright (C) 2010 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 +// . +// + +#include +#include +#include +#ifndef _GLIBCXX_DEBUG +# include +# include +# include +#endif +#include + +namespace __gnu_test +{ + template + struct CopyableValueType + { + typedef _Tp value_type; + }; + + template + struct CopyableValueType > + { + typedef std::pair<_Tp1, _Tp2> value_type; + }; + + template + struct generate_unique + { + typedef _Tp value_type; + + operator value_type() + { + static value_type _S_; + ++_S_; + return _S_; + } + }; + + template + struct generate_unique > + { + typedef _Tp1 first_type; + typedef _Tp2 second_type; + typedef std::pair<_Tp1, _Tp2> pair_type; + + operator pair_type() + { + static first_type _S_1; + static second_type _S_2; + ++_S_1; + ++_S_2; + return pair_type(_S_1, _S_2); + } + }; + + // Check that invalid range of pointers is detected + template + void + check_assign1() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + const val_type* first = &v.front() + 1; + const val_type* last = first + 2; + + cont_type c1; + c1.assign(first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + c2.assign(last, first); // Expected failure + } + + // Check that invalid range of debug random iterators is detected + template + void + check_assign2() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + typename vector_type::iterator first = v.begin() + 1; + typename vector_type::iterator last = first + 2; + cont_type c1; + c1.assign(first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + c2.assign(last, first); // Expected failure + } + + // Check that invalid range of debug !random debug iterators is detected + template + void + check_assign3() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::list list_type; + + generate_unique gu; + + list_type l; + for (int i = 0; i != 5; ++i) + l.push_back(gu); + VERIFY(l.size() == 5); + + typename list_type::iterator first = l.begin(); ++first; + typename list_type::iterator last = first; ++last; ++last; + cont_type c1; + c1.assign(first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + c2.assign(last, first); // Expected failure + } + + // Check that invalid range of pointers is detected + template + void + check_construct1() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + val_type *first = &v.front() + 1; + val_type *last = first + 2; + cont_type c1(first, last); + VERIFY(c1.size() == 2); + + cont_type c2(last, first); // Expected failure + } + + // Check that invalid range of debug random iterators is detected + template + void + check_construct2() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + typename vector_type::iterator first = v.begin() + 1; + typename vector_type::iterator last = first + 2; + cont_type c1(first, last); + VERIFY(c1.size() == 2); + + cont_type c2(last, first); // Expected failure + } + + // Check that invalid range of debug not random iterators is detected + template + void + check_construct3() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::list list_type; + + generate_unique gu; + + list_type l; + for (int i = 0; i != 5; ++i) + l.push_back(gu); + VERIFY(l.size() == 5); + + typename list_type::iterator first = l.begin(); ++first; + typename list_type::iterator last = first; ++last; ++last; + cont_type c1(first, last); + VERIFY(c1.size() == 2); + + cont_type c2(last, first); // Expected failure + } + + template + struct InsertRangeHelper + { + template + static void + Insert(_Cont& cont, _It first, _It last) + { cont.insert(first, last); } + }; + + template + struct InsertRangeHelperAux + { + template + static void + Insert(_Cont& cont, _It first, _It last) + { cont.insert(cont.begin(), first, last); } + }; + + template + struct InsertRangeHelper > + : InsertRangeHelperAux > + { }; + + template + struct InsertRangeHelper > + : InsertRangeHelperAux > + { }; + + template + struct InsertRangeHelper > + : InsertRangeHelperAux > + { }; + +#ifndef _GLIBCXX_DEBUG + template + struct InsertRangeHelper<__gnu_debug::vector<_Tp1, _Tp2> > + : InsertRangeHelperAux<__gnu_debug::vector<_Tp1, _Tp2> > + { }; + + template + struct InsertRangeHelper<__gnu_debug::deque<_Tp1, _Tp2> > + : InsertRangeHelperAux<__gnu_debug::deque<_Tp1, _Tp2> > + { }; + + template + struct InsertRangeHelper<__gnu_debug::list<_Tp1, _Tp2> > + : InsertRangeHelperAux<__gnu_debug::list<_Tp1, _Tp2> > + { }; +#endif + + template + void + check_insert1() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + const val_type* first = &v.front() + 1; + const val_type* last = first + 2; + + cont_type c1; + InsertRangeHelper::Insert(c1, first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + InsertRangeHelper::Insert(c2, last, first); // Expected failure + } + + template + void + check_insert2() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::vector vector_type; + + generate_unique gu; + + vector_type v; + for (int i = 0; i != 5; ++i) + v.push_back(gu); + VERIFY(v.size() == 5); + + typename vector_type::iterator first = v.begin() + 1; + typename vector_type::iterator last = first + 2; + + cont_type c1; + InsertRangeHelper::Insert(c1, first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + InsertRangeHelper::Insert(c2, last, first); // Expected failure + } + + template + void + check_insert3() + { + bool test __attribute__((unused)) = true; + + typedef _Tp cont_type; + typedef typename cont_type::value_type cont_val_type; + typedef typename CopyableValueType::value_type val_type; + typedef std::list list_type; + + generate_unique gu; + + list_type l; + for (int i = 0; i != 5; ++i) + l.push_back(gu); + VERIFY(l.size() == 5); + + typename list_type::iterator first = l.begin(); ++first; + typename list_type::iterator last = first; ++last; ++last; + + cont_type c1; + InsertRangeHelper::Insert(c1, first, last); + VERIFY(c1.size() == 2); + + cont_type c2; + InsertRangeHelper::Insert(c2, last, first); // Expected failure + } +} + -- cgit v1.2.3