pointer.h: Add experimental support for non-standard pointer types in containers via the...
2008-11-07 Bob Walters <bob.s.walters@gmail.com> * include/ext/pointer.h: Add experimental support for non-standard pointer types in containers via the allocator::pointer typedef. (Currently only supported/working with std::vector) * include/ext/cast.h: Add overload-able pointer casting functions for use in containers supporting non-standard pointer types. * include/ext/extptr_allocator.h: Add _ExtPtr_allocator. * include/Makefile.am: Update. * include/precompiled/extc++.h: Likewise. * include/Makefile.in: Regenerate. * testsuite/ext/ext_pointer/1.cc: New. * testsuite/ext/ext_pointer/1_neg.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/citerators.cc: New. * testsuite/23_containers/vector/ext_pointer/data_access.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/resize.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/types/1.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/modifiers/element.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/modifiers/erase.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/modifiers/insert.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/explicit_instantiation/ 1.cc: Likewise. * testsuite/23_containers/vector/ext_pointer/explicit_instantiation/ 3.cc: Likewise. From-SVN: r141674
This commit is contained in:
parent
7fee6a39eb
commit
b74318f12b
@ -1,3 +1,31 @@
|
||||
2008-11-07 Bob Walters <bob.s.walters@gmail.com>
|
||||
|
||||
* include/ext/pointer.h: Add experimental support for non-standard
|
||||
pointer types in containers via the allocator::pointer typedef.
|
||||
(Currently only supported/working with std::vector)
|
||||
* include/ext/cast.h: Add overload-able pointer casting functions
|
||||
for use in containers supporting non-standard pointer types.
|
||||
* include/ext/extptr_allocator.h: Add _ExtPtr_allocator.
|
||||
* include/Makefile.am: Update.
|
||||
* include/precompiled/extc++.h: Likewise.
|
||||
* include/Makefile.in: Regenerate.
|
||||
* testsuite/ext/ext_pointer/1.cc: New.
|
||||
* testsuite/ext/ext_pointer/1_neg.cc: Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/citerators.cc: New.
|
||||
* testsuite/23_containers/vector/ext_pointer/data_access.cc: Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/resize.cc: Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/types/1.cc: Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/modifiers/element.cc:
|
||||
Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/modifiers/erase.cc:
|
||||
Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/modifiers/insert.cc:
|
||||
Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/explicit_instantiation/
|
||||
1.cc: Likewise.
|
||||
* testsuite/23_containers/vector/ext_pointer/explicit_instantiation/
|
||||
3.cc: Likewise.
|
||||
|
||||
2008-11-05 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
PR libstdc++/38017
|
||||
|
@ -484,10 +484,12 @@ ext_headers = \
|
||||
${ext_srcdir}/atomicity.h \
|
||||
${ext_srcdir}/array_allocator.h \
|
||||
${ext_srcdir}/bitmap_allocator.h \
|
||||
${ext_srcdir}/cast.h \
|
||||
${ext_srcdir}/codecvt_specializations.h \
|
||||
${ext_srcdir}/concurrence.h \
|
||||
${ext_srcdir}/debug_allocator.h \
|
||||
${ext_srcdir}/enc_filebuf.h \
|
||||
${ext_srcdir}/extptr_allocator.h \
|
||||
${ext_srcdir}/stdio_filebuf.h \
|
||||
${ext_srcdir}/stdio_sync_filebuf.h \
|
||||
${ext_srcdir}/functional \
|
||||
@ -499,6 +501,7 @@ ext_headers = \
|
||||
${ext_srcdir}/numeric \
|
||||
${ext_srcdir}/numeric_traits.h \
|
||||
${ext_srcdir}/pod_char_traits.h \
|
||||
${ext_srcdir}/pointer.h \
|
||||
${ext_srcdir}/pool_allocator.h \
|
||||
${ext_srcdir}/rb_tree \
|
||||
${ext_srcdir}/rope \
|
||||
|
@ -748,10 +748,12 @@ ext_headers = \
|
||||
${ext_srcdir}/atomicity.h \
|
||||
${ext_srcdir}/array_allocator.h \
|
||||
${ext_srcdir}/bitmap_allocator.h \
|
||||
${ext_srcdir}/cast.h \
|
||||
${ext_srcdir}/codecvt_specializations.h \
|
||||
${ext_srcdir}/concurrence.h \
|
||||
${ext_srcdir}/debug_allocator.h \
|
||||
${ext_srcdir}/enc_filebuf.h \
|
||||
${ext_srcdir}/extptr_allocator.h \
|
||||
${ext_srcdir}/stdio_filebuf.h \
|
||||
${ext_srcdir}/stdio_sync_filebuf.h \
|
||||
${ext_srcdir}/functional \
|
||||
@ -763,6 +765,7 @@ ext_headers = \
|
||||
${ext_srcdir}/numeric \
|
||||
${ext_srcdir}/numeric_traits.h \
|
||||
${ext_srcdir}/pod_char_traits.h \
|
||||
${ext_srcdir}/pointer.h \
|
||||
${ext_srcdir}/pool_allocator.h \
|
||||
${ext_srcdir}/rb_tree \
|
||||
${ext_srcdir}/rope \
|
||||
|
@ -1,6 +1,6 @@
|
||||
// C++ includes used for precompiling extensions -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2006, 2007 Free Software Foundation, Inc.
|
||||
// Copyright (C) 2006, 2007, 2008 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
|
||||
@ -37,8 +37,10 @@
|
||||
#include <ext/array_allocator.h>
|
||||
#include <ext/atomicity.h>
|
||||
#include <ext/bitmap_allocator.h>
|
||||
#include <ext/cast.h>
|
||||
#include <ext/concurrence.h>
|
||||
#include <ext/debug_allocator.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
#include <ext/functional>
|
||||
#include <ext/iterator>
|
||||
#include <ext/malloc_allocator.h>
|
||||
@ -47,6 +49,7 @@
|
||||
#include <ext/new_allocator.h>
|
||||
#include <ext/numeric>
|
||||
#include <ext/pod_char_traits.h>
|
||||
#include <ext/pointer.h>
|
||||
#include <ext/pool_allocator.h>
|
||||
#include <ext/rb_tree>
|
||||
#include <ext/rope>
|
||||
|
@ -0,0 +1,55 @@
|
||||
// { dg-options "-std=gnu++0x" }
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
// Ensures equivalence of iterators based on low-level comparison
|
||||
// between const / non-const Pointer types.
|
||||
void
|
||||
test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > v(7);
|
||||
VERIFY( v.cbegin() == v.begin() );
|
||||
VERIFY( v.cend() == v.end() );
|
||||
VERIFY( v.crbegin() == v.rbegin() );
|
||||
VERIFY( v.crend() == v.rend() );
|
||||
VERIFY( v.cbegin() != v.cend() );
|
||||
VERIFY( v.crbegin() != v.crend() );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
// libstdc++/23578
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
typedef std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > vector_type;
|
||||
|
||||
{
|
||||
const int A[] = { 0, 1, 2, 3, 4 };
|
||||
vector_type v(A, A + 5);
|
||||
VERIFY( v.data() == &v.front() );
|
||||
int* pi = &* v.data();
|
||||
VERIFY( *pi == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
const int A[] = { 4, 3, 2, 1, 0 };
|
||||
const vector_type cv(A, A + 5);
|
||||
VERIFY( cv.data() == &cv.front() );
|
||||
const int* pci = &* cv.data();
|
||||
VERIFY( *pci == 4 );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
// { dg-do compile }
|
||||
|
||||
template class std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> >;
|
@ -0,0 +1,37 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
// { dg-do compile }
|
||||
|
||||
// libstdc++/21770
|
||||
template class std::vector<int, __gnu_cxx::_ExtPtr_allocator<char> >;
|
@ -0,0 +1,86 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
// General tests element access and manipulation
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
int A[] = { 0, 1, 2, 3, 4 };
|
||||
__gnu_cxx::_ExtPtr_allocator<int> alloc;
|
||||
std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > mv( A, A+5, alloc );
|
||||
|
||||
VERIFY( mv.size() == 5 );
|
||||
VERIFY( mv.front() == 0 );
|
||||
VERIFY( mv.back() == 4 );
|
||||
VERIFY( mv.at(2) == 2 );
|
||||
VERIFY( mv[3] == 3);
|
||||
mv.front() = 5;
|
||||
mv.back() = 6;
|
||||
mv.at(2) = 7;
|
||||
mv[3] = 8;
|
||||
VERIFY( mv.size() == 5 );
|
||||
VERIFY( mv.front() == 5 );
|
||||
VERIFY( mv.back() == 6 );
|
||||
VERIFY( mv.at(2) == 7 );
|
||||
VERIFY( mv[3] == 8 );
|
||||
|
||||
try
|
||||
{
|
||||
mv.at(100) = 8;
|
||||
}
|
||||
catch(std::out_of_range&)
|
||||
{
|
||||
VERIFY( true );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
|
||||
const std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > cmv( mv );
|
||||
VERIFY( cmv.get_allocator() == mv.get_allocator() );
|
||||
VERIFY( mv.size() == 5 );
|
||||
VERIFY( mv.front() == 5 );
|
||||
VERIFY( mv.back() == 6 );
|
||||
VERIFY( mv.at(2) == 7 );
|
||||
VERIFY( mv[3] == 8 );
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
// Bob Walters 10-2008
|
||||
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||
const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
|
||||
const int A3[] = {0, 2, 3, 4, 10, 11};
|
||||
const int A4[] = {4, 10, 11};
|
||||
const int A5[] = {4, 10};
|
||||
const unsigned int N = sizeof(A) / sizeof(int);
|
||||
const unsigned int N1 = sizeof(A1) / sizeof(int);
|
||||
const unsigned int N2 = sizeof(A2) / sizeof(int);
|
||||
const unsigned int N3 = sizeof(A3) / sizeof(int);
|
||||
const unsigned int N4 = sizeof(A4) / sizeof(int);
|
||||
const unsigned int N5 = sizeof(A5) / sizeof(int);
|
||||
|
||||
void
|
||||
test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
typedef std::vector<int,__gnu_cxx::_ExtPtr_allocator<int> > vec_type;
|
||||
typedef vec_type::iterator iterator_type;
|
||||
|
||||
vec_type v(A, A + N);
|
||||
std::cout << v.size() << std::endl;
|
||||
std::cout << v.capacity() << std::endl;
|
||||
std::cout << v.max_size() << std::endl;
|
||||
|
||||
iterator_type it1 = v.erase(v.begin() + 1);
|
||||
VERIFY( it1 == v.begin() + 1 );
|
||||
std::cout << N << std::endl << v.size() << std::endl;
|
||||
VERIFY( v.size() == N1 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), A1) );
|
||||
|
||||
iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
|
||||
VERIFY( it2 == v.begin() + 4 );
|
||||
VERIFY( v.size() == N2 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), A2) );
|
||||
|
||||
iterator_type it3 = v.erase(v.begin() + 6, v.end());
|
||||
VERIFY( it3 == v.begin() + 6 );
|
||||
VERIFY( v.size() == N3 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), A3) );
|
||||
|
||||
iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
|
||||
VERIFY( it4 == v.begin() );
|
||||
VERIFY( v.size() == N4 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), A4) );
|
||||
|
||||
iterator_type it5 = v.erase(v.begin() + 2);
|
||||
VERIFY( it5 == v.begin() + 2 );
|
||||
VERIFY( v.size() == N5 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), A5) );
|
||||
|
||||
iterator_type it6 = v.erase(v.begin(), v.end());
|
||||
VERIFY( it6 == v.begin() );
|
||||
VERIFY( v.empty() );
|
||||
}
|
||||
|
||||
void
|
||||
test02()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
typedef __gnu_cxx::_ExtPtr_allocator<int> int_alloc_type;
|
||||
typedef __gnu_cxx::_ExtPtr_allocator< std::vector<int, int_alloc_type> > vec_alloc_type;
|
||||
typedef std::vector<std::vector<int, int_alloc_type >,vec_alloc_type> vec_type;
|
||||
typedef vec_type::iterator iterator_type;
|
||||
|
||||
vec_type v, v1, v2, v3, v4, v5;
|
||||
for (unsigned int i = 0; i < N; ++i)
|
||||
v.push_back(std::vector<int,int_alloc_type>(1, A[i]));
|
||||
for (unsigned int i = 0; i < N1; ++i)
|
||||
v1.push_back(std::vector<int,int_alloc_type>(1, A1[i]));
|
||||
for (unsigned int i = 0; i < N2; ++i)
|
||||
v2.push_back(std::vector<int,int_alloc_type>(1, A2[i]));
|
||||
for (unsigned int i = 0; i < N3; ++i)
|
||||
v3.push_back(std::vector<int,int_alloc_type>(1, A3[i]));
|
||||
for (unsigned int i = 0; i < N4; ++i)
|
||||
v4.push_back(std::vector<int,int_alloc_type>(1, A4[i]));
|
||||
for (unsigned int i = 0; i < N5; ++i)
|
||||
v5.push_back(std::vector<int,int_alloc_type>(1, A5[i]));
|
||||
|
||||
iterator_type it1 = v.erase(v.begin() + 1);
|
||||
VERIFY( it1 == v.begin() + 1 );
|
||||
VERIFY( v.size() == N1 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
|
||||
|
||||
iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
|
||||
VERIFY( it2 == v.begin() + 4 );
|
||||
VERIFY( v.size() == N2 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
|
||||
|
||||
iterator_type it3 = v.erase(v.begin() + 6, v.end());
|
||||
VERIFY( it3 == v.begin() + 6 );
|
||||
VERIFY( v.size() == N3 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
|
||||
|
||||
iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
|
||||
VERIFY( it4 == v.begin() );
|
||||
VERIFY( v.size() == N4 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
|
||||
|
||||
iterator_type it5 = v.erase(v.begin() + 2);
|
||||
VERIFY( it5 == v.begin() + 2 );
|
||||
VERIFY( v.size() == N5 );
|
||||
VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
|
||||
|
||||
iterator_type it6 = v.erase(v.begin(), v.end());
|
||||
VERIFY( it6 == v.begin() );
|
||||
VERIFY( v.empty() );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
#include <stdexcept>
|
||||
|
||||
void test01()
|
||||
{
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
__gnu_cxx::_ExtPtr_allocator<int> alloc;
|
||||
std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > iv(alloc);
|
||||
VERIFY( iv.get_allocator() == alloc );
|
||||
VERIFY( iv.size() == 0 );
|
||||
|
||||
int A[] = { 0, 1, 2, 3, 4 };
|
||||
int B[] = { 5, 5, 5, 5, 5 };
|
||||
int C[] = { 6, 7 };
|
||||
iv.insert(iv.end(), A, A+5 );
|
||||
VERIFY( iv.size() == 5 );
|
||||
iv.insert(iv.begin(), 5, 5 );
|
||||
iv.insert(iv.begin()+5, 7);
|
||||
iv.insert(iv.begin()+5, 6);
|
||||
VERIFY( std::equal(iv.begin(), iv.begin()+5, B ));
|
||||
VERIFY( std::equal(iv.begin()+5, iv.begin()+7, C));
|
||||
VERIFY( std::equal(iv.begin()+7, iv.end(), A));
|
||||
VERIFY( iv.size() == 12 );
|
||||
|
||||
try
|
||||
{
|
||||
iv.insert(iv.end(), iv.max_size() + 1, 1);
|
||||
}
|
||||
catch(std::length_error&)
|
||||
{
|
||||
VERIFY( true );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
VERIFY( false );
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
#include <testsuite_allocator.h>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
|
||||
void test01()
|
||||
{
|
||||
// non POD types
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> > vec01;
|
||||
typedef std::vector<int, __gnu_cxx::_ExtPtr_allocator<int> >::size_type size_type;
|
||||
|
||||
VERIFY(vec01.empty());
|
||||
|
||||
const int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
// Test resize of the vector based on reserve
|
||||
size_type sz01 = vec01.capacity();
|
||||
vec01.reserve(100);
|
||||
size_type sz02 = vec01.capacity();
|
||||
VERIFY(sz02 >= sz01);
|
||||
|
||||
// grow/shrink
|
||||
vec01.assign( A, A+10 );
|
||||
sz01 = vec01.size() + 100;
|
||||
vec01.resize(sz01);
|
||||
sz02 = vec01.size();
|
||||
VERIFY(sz01 == sz02);
|
||||
VERIFY(std::equal(vec01.begin(), vec01.begin()+10, A));
|
||||
|
||||
sz01 = vec01.size() - 100;
|
||||
vec01.resize(sz01);
|
||||
sz02 = vec01.size();
|
||||
VERIFY(sz01 == sz02);
|
||||
VERIFY(std::equal(vec01.begin(), vec01.end(), A));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
// This is a copy of vector/types/1.cc with altered allocator.
|
||||
// The operator+()s in this test initially failed the test -
|
||||
// they stress the accurate recognition, by the compiler,
|
||||
// of _Pointer_adapter's own pointer arithmetic functions,
|
||||
// which have to match perfectly on the int type to get
|
||||
// chosen by the compiler when it sees: _Pointer_adapter<T> + int, etc.
|
||||
|
||||
#include <vector>
|
||||
#include <ext/extptr_allocator.h>
|
||||
|
||||
namespace N
|
||||
{
|
||||
struct X { };
|
||||
|
||||
template<typename T>
|
||||
X operator+(T, std::size_t)
|
||||
{ return X(); }
|
||||
|
||||
template<typename T>
|
||||
X operator-(T, T)
|
||||
{ return X(); }
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > v(5);
|
||||
const std::vector<N::X, __gnu_cxx::_ExtPtr_allocator<N::X> > w(1);
|
||||
|
||||
v[0];
|
||||
w[0];
|
||||
v.size();
|
||||
v.capacity();
|
||||
v.resize(1);
|
||||
v.insert(v.begin(), N::X());
|
||||
v.insert(v.begin(), 1, N::X());
|
||||
v.insert(v.begin(), w.begin(), w.end());
|
||||
v = w;
|
||||
|
||||
return 0;
|
||||
}
|
208
libstdc++-v3/testsuite/ext/ext_pointer/1.cc
Normal file
208
libstdc++-v3/testsuite/ext/ext_pointer/1.cc
Normal file
@ -0,0 +1,208 @@
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
#include <algorithm>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/cast.h>
|
||||
#include <ext/pointer.h>
|
||||
|
||||
using __gnu_cxx::_Pointer_adapter;
|
||||
using __gnu_cxx::_Relative_pointer_impl;
|
||||
using __gnu_cxx::__static_pointer_cast;
|
||||
using __gnu_cxx::__const_pointer_cast;
|
||||
|
||||
|
||||
void
|
||||
test01() {
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<int> > pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<const int> > const_pointer;
|
||||
|
||||
int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
// basic pointer assignment/access tests.
|
||||
pointer x = &A[0];
|
||||
VERIFY(*x == 0);
|
||||
VERIFY(std::equal(x, x+10, A));
|
||||
pointer y(&A[9]);
|
||||
VERIFY(*y == 9);
|
||||
|
||||
// assignability
|
||||
pointer z(x);
|
||||
VERIFY(z==x);
|
||||
VERIFY(*z == 0);
|
||||
|
||||
z = y;
|
||||
VERIFY(z==y);
|
||||
VERIFY(z!=x);
|
||||
VERIFY(z>x);
|
||||
VERIFY(*z == 9);
|
||||
|
||||
// pointer arithmetic
|
||||
VERIFY(*++x == 1);
|
||||
VERIFY(*--x == 0);
|
||||
VERIFY(*(x++) == 0);
|
||||
VERIFY(*(x--) == 1);
|
||||
VERIFY(*(x+2) == 2);
|
||||
VERIFY(*(2+x) == 2);
|
||||
VERIFY(*(y-2) == 7);
|
||||
VERIFY(y - x == 9);
|
||||
VERIFY(&*y - x == 9);
|
||||
VERIFY(y - &*x == 9);
|
||||
|
||||
size_t s(y - x);
|
||||
VERIFY(s == 9);
|
||||
}
|
||||
|
||||
|
||||
struct A {
|
||||
mutable int i;
|
||||
};
|
||||
struct B : public A{
|
||||
mutable int j;
|
||||
};
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<B> > B_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<A> > A_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<const A> > const_A_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<const B> > const_B_pointer;
|
||||
|
||||
|
||||
// Test implicit conversion from B* to A*
|
||||
void inc(_Pointer_adapter<_Relative_pointer_impl<A> > a) {
|
||||
a->i++;
|
||||
}
|
||||
// Test implicit conversion from B* to const B*
|
||||
void inc2(_Pointer_adapter<_Relative_pointer_impl<const B> > b) {
|
||||
b->i++;
|
||||
b->j++;
|
||||
}
|
||||
// Test implicit conversion from B* to const A*
|
||||
void inc3(_Pointer_adapter<_Relative_pointer_impl<const A> > a) {
|
||||
a->i++;
|
||||
}
|
||||
|
||||
void test02() {
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
B b;
|
||||
b.i = 2;
|
||||
b.j = 2;
|
||||
|
||||
B_pointer Bptr(&b);
|
||||
VERIFY(Bptr->i == 2);
|
||||
Bptr->i++;
|
||||
VERIFY(b.i == 3);
|
||||
|
||||
const_B_pointer cBptr(&b);
|
||||
b.i++;
|
||||
VERIFY(cBptr->i == 4);
|
||||
|
||||
A_pointer Aptr(&b);
|
||||
b.i++;
|
||||
VERIFY(Aptr->i == 5);
|
||||
Aptr->i++;
|
||||
VERIFY(b.i == 6);
|
||||
|
||||
const_A_pointer cAptr(&b);
|
||||
b.i++;
|
||||
VERIFY(cAptr->i == 7);
|
||||
|
||||
const_B_pointer cBptr2(Bptr);
|
||||
b.i++;
|
||||
VERIFY(cBptr2->i == 8);
|
||||
|
||||
A_pointer Aptr2(Bptr);
|
||||
b.i++;
|
||||
VERIFY(Aptr2->i == 9);
|
||||
Aptr2->i++;
|
||||
VERIFY(b.i == 10);
|
||||
|
||||
const_A_pointer cAptr2(Bptr);
|
||||
b.i++;
|
||||
VERIFY(cAptr2->i == 11);
|
||||
|
||||
// Implicit casting during invocation
|
||||
inc(Bptr);
|
||||
VERIFY(Bptr->i == 12);
|
||||
inc2(Bptr);
|
||||
VERIFY(Bptr->i == 13);
|
||||
VERIFY(Bptr->j == 3);
|
||||
inc3(Bptr);
|
||||
VERIFY(Bptr->i == 14);
|
||||
}
|
||||
|
||||
void test03() {
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
B b;
|
||||
B* bPtr = &b;
|
||||
A* aPtr __attribute__((unused)) = __static_pointer_cast<A*>(bPtr);
|
||||
const A *caPtr __attribute__((unused)) = __static_pointer_cast<const A*>(bPtr);
|
||||
const B *cbPtr __attribute__((unused)) = __static_pointer_cast<const B*>(bPtr);
|
||||
|
||||
B_pointer Bptr2 = &b;
|
||||
|
||||
const A* caPtr2 __attribute__((unused)) = __static_pointer_cast<const A*>(Bptr2);
|
||||
A * aPtr2 __attribute__((unused)) = __static_pointer_cast<A*>(Bptr2);
|
||||
const B* cbPtr2 __attribute__((unused)) = __const_pointer_cast<const B*>(Bptr2);
|
||||
|
||||
const_A_pointer caPtr3 __attribute__((unused)) = __static_pointer_cast<const A*>(Bptr2);
|
||||
A_pointer aPtr3 __attribute__((unused)) = __static_pointer_cast<A*>(Bptr2);
|
||||
const_B_pointer cbPtr3 __attribute__((unused)) = __const_pointer_cast<const B*>(Bptr2);
|
||||
}
|
||||
|
||||
// Confirm the usability of the __static_pointer_cast<> template function
|
||||
// to transform between _Pointer_adapter and standard versions.
|
||||
void test04() {
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
B b;
|
||||
B_pointer bPtr = &b;
|
||||
|
||||
A_pointer aPtr = __static_pointer_cast<A_pointer>(bPtr);
|
||||
VERIFY(aPtr == bPtr);
|
||||
B_pointer bPtr2 = __static_pointer_cast<B_pointer>(aPtr);
|
||||
VERIFY(bPtr2 == aPtr);
|
||||
|
||||
A* aPtr3 = __static_pointer_cast<A*>(bPtr);
|
||||
VERIFY(aPtr3 == bPtr);
|
||||
B* bPtr3 = __static_pointer_cast<B*>(aPtr);
|
||||
VERIFY(bPtr3 == aPtr);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
return 0;
|
||||
}
|
112
libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
Normal file
112
libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc
Normal file
@ -0,0 +1,112 @@
|
||||
// Bob Walters 10-2008
|
||||
|
||||
// Test for Container using non-standard pointer types.
|
||||
|
||||
// Copyright (C) 2008
|
||||
// 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 2, 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
// USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free software
|
||||
// library without restriction. Specifically, if other files instantiate
|
||||
// templates or use macros or inline functions from this file, or you compile
|
||||
// this file and link it with other files to produce an executable, this
|
||||
// file does not by itself cause the resulting executable to be covered by
|
||||
// the GNU General Public License. This exception does not however
|
||||
// invalidate any other reasons why the executable file might be covered by
|
||||
// the GNU General Public License.
|
||||
|
||||
// { dg-do compile }
|
||||
|
||||
#include <algorithm>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <ext/pointer.h>
|
||||
|
||||
using __gnu_cxx::_Pointer_adapter;
|
||||
using __gnu_cxx::_Relative_pointer_impl;
|
||||
using __gnu_cxx::__static_pointer_cast;
|
||||
using __gnu_cxx::__const_pointer_cast;
|
||||
|
||||
|
||||
struct A {
|
||||
int i;
|
||||
};
|
||||
struct B : public A{
|
||||
int j;
|
||||
};
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<B> > B_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<const B> > const_B_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<A> > A_pointer;
|
||||
typedef _Pointer_adapter<_Relative_pointer_impl<const A> > const_A_pointer;
|
||||
|
||||
|
||||
void test01(void) {
|
||||
bool test __attribute__((unused)) = true;
|
||||
|
||||
A a;
|
||||
B b;
|
||||
|
||||
A_pointer aptr( &a );
|
||||
|
||||
// Can't implicitly cast from A* to B*
|
||||
B_pointer bptr1(aptr); // { dg-error "instantiated from here" 31 }
|
||||
B_pointer bptr2(&a); // { dg-error "instantiated from here" 32 }
|
||||
|
||||
// but explicit cast/conversion is OK.
|
||||
B_pointer bptr3(__static_pointer_cast<B_pointer>(aptr)); // ok
|
||||
B_pointer bptr4(__static_pointer_cast<B_pointer>(&a)); // ok
|
||||
|
||||
// Can't implicitly cast from A* to B*
|
||||
bptr1 = aptr; // { dg-error "instantiated from here" 39 }
|
||||
bptr1 = &a; // { dg-error "instantiated from here" 40 }
|
||||
|
||||
// but explicit cast/conversion is OK.
|
||||
bptr1 = __static_pointer_cast<B_pointer>(aptr); // ok
|
||||
bptr1 = __static_pointer_cast<B_pointer>(&a); // ok
|
||||
|
||||
// Similarly, can't shed constness via implicit cast
|
||||
const_A_pointer captr(&a);
|
||||
A_pointer aptr2(captr); // { dg-error "instantiated from here" 48 }
|
||||
|
||||
// but explicit cast/conversion is OK.
|
||||
A_pointer aptr3(__const_pointer_cast<A_pointer>(captr)); // ok
|
||||
|
||||
// Similarly, can't shed constness via implicit cast
|
||||
aptr2 = captr; // { dg-error "instantiated from here" 54 }
|
||||
|
||||
// but explicit cast/conversion is OK.
|
||||
aptr3 = __const_pointer_cast<A_pointer>(captr); // ok
|
||||
|
||||
// Combine explicit const cast with implicit downcast.
|
||||
const_B_pointer cbptr(&b);
|
||||
A_pointer aptr4(cbptr); // { dg-error "instantiated from here" 61 }
|
||||
aptr4 = cbptr; // { dg-error "instantiated from here" 62 }
|
||||
|
||||
A_pointer aptr5(__const_pointer_cast<B_pointer>(cbptr)); // ok
|
||||
aptr5 = __const_pointer_cast<B_pointer>(cbptr); // ok
|
||||
}
|
||||
|
||||
// { dg-error "invalid conversion " "" { target *-*-* } 334 }
|
||||
// { dg-error "initializing argument 1 of" "" { target *-*-* } 334 }
|
||||
// { dg-error "invalid conversion " "" { target *-*-* } 324 }
|
||||
// { dg-error "initializing argument 1 of" "" { target *-*-* } 324 }
|
||||
// { dg-error "invalid conversion " "" { target *-*-* } 352 }
|
||||
// { dg-error "initializing argument 1 of" "" { target *-*-* } 352 }
|
||||
// { dg-error "invalid conversion " "" { target *-*-* } 360 }
|
||||
// { dg-error "initializing argument 1 of" "" { target *-*-* } 360 }
|
||||
// { dg-excess-errors "In constructor" }
|
||||
|
Loading…
Reference in New Issue
Block a user