diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libstdc++-v3/testsuite/experimental | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libstdc++-v3/testsuite/experimental')
106 files changed, 7879 insertions, 0 deletions
diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/1.cc new file mode 100644 index 000000000..5a7041bf7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/1.cc @@ -0,0 +1,195 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct exception {}; + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter +{ + enum state_type + { + zero, + moved_from, + throwing_construction, + throwing_copy, + throwing_copy_assignment, + throwing_move, + throwing_move_assignment, + threw, + }; + + value_type() = default; + + explicit value_type(state_type state_) + : state(state_) + { + throw_if(throwing_construction); + } + + value_type(value_type const& other) + : state(other.state) + { + throw_if(throwing_copy); + } + + value_type& + operator=(value_type const& other) + { + state = other.state; + throw_if(throwing_copy_assignment); + return *this; + } + + value_type(value_type&& other) + : state(other.state) + { + other.state = moved_from; + throw_if(throwing_move); + } + + value_type& + operator=(value_type&& other) + { + state = other.state; + other.state = moved_from; + throw_if(throwing_move_assignment); + return *this; + } + + void throw_if(state_type match) + { + if(state == match) + { + state = threw; + throw exception {}; + } + } + + state_type state = zero; +}; + +int main() +{ + using O = std::experimental::optional<value_type>; + using S = value_type::state_type; + auto const make = [](S s = S::zero) { return O { std::experimental::in_place, s }; }; + + enum outcome_type { nothrow, caught, bad_catch }; + + // Check copy/move assignment for disengaged optional + + // From disengaged optional + { + O o; + VERIFY( !o ); + O p; + o = p; + VERIFY( !o ); + VERIFY( !p ); + } + + { + O o; + VERIFY( !o ); + O p; + o = std::move(p); + VERIFY( !o ); + VERIFY( !p ); + } + + { + O o; + VERIFY( !o ); + o = {}; + VERIFY( !o ); + } + + // From engaged optional + { + O o; + VERIFY( !o ); + O p = make(S::throwing_copy_assignment); + o = p; + VERIFY( o && o->state == S::throwing_copy_assignment ); + VERIFY( p && p->state == S::throwing_copy_assignment ); + } + + { + O o; + VERIFY( !o ); + O p = make(S::throwing_move_assignment); + o = std::move(p); + VERIFY( o && o->state == S::throwing_move_assignment ); + VERIFY( p && p->state == S::moved_from ); + } + + { + outcome_type outcome {}; + O o; + VERIFY( !o ); + O p = make(S::throwing_copy); + + try + { + o = p; + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( outcome == caught ); + VERIFY( !o ); + VERIFY( p && p->state == S::throwing_copy ); + } + + { + outcome_type outcome {}; + O o; + VERIFY( !o ); + O p = make(S::throwing_move); + + try + { + o = std::move(p); + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( outcome == caught ); + VERIFY( !o ); + VERIFY( p && p->state == S::moved_from ); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/2.cc new file mode 100644 index 000000000..c19943f1c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/2.cc @@ -0,0 +1,193 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct exception {}; + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter +{ + enum state_type + { + zero, + moved_from, + throwing_construction, + throwing_copy, + throwing_copy_assignment, + throwing_move, + throwing_move_assignment, + threw, + }; + + value_type() = default; + + explicit value_type(state_type state_) + : state(state_) + { + throw_if(throwing_construction); + } + + value_type(value_type const& other) + : state(other.state) + { + throw_if(throwing_copy); + } + + value_type& + operator=(value_type const& other) + { + state = other.state; + throw_if(throwing_copy_assignment); + return *this; + } + + value_type(value_type&& other) + : state(other.state) + { + other.state = moved_from; + throw_if(throwing_move); + } + + value_type& + operator=(value_type&& other) + { + state = other.state; + other.state = moved_from; + throw_if(throwing_move_assignment); + return *this; + } + + void throw_if(state_type match) + { + if(state == match) + { + state = threw; + throw exception {}; + } + } + + state_type state = zero; +}; + +int main() +{ + using O = std::experimental::optional<value_type>; + using S = value_type::state_type; + auto const make = [](S s = S::zero) { return O { std::experimental::in_place, s }; }; + + enum outcome_type { nothrow, caught, bad_catch }; + + // Check copy/move assignment for engaged optional + + // From disengaged optional + { + O o = make(S::zero); + VERIFY( o ); + O p; + o = p; + VERIFY( !o ); + VERIFY( !p ); + } + + { + O o = make(S::zero); + VERIFY( o ); + O p; + o = std::move(p); + VERIFY( !o ); + VERIFY( !p ); + } + + { + O o = make(S::zero); + VERIFY( o ); + o = {}; + VERIFY( !o ); + } + + // From engaged optional + { + O o = make(S::zero); + VERIFY( o ); + O p = make(S::throwing_copy); + o = p; + VERIFY( o && o->state == S::throwing_copy); + VERIFY( p && p->state == S::throwing_copy); + } + + { + O o = make(S::zero); + VERIFY( o ); + O p = make(S::throwing_move); + o = std::move(p); + VERIFY( o && o->state == S::throwing_move); + VERIFY( p && p->state == S::moved_from); + } + + { + outcome_type outcome {}; + O o = make(S::zero); + VERIFY( o ); + O p = make(S::throwing_copy_assignment); + + try + { + o = p; + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( o && o->state == S::threw); + VERIFY( p && p->state == S::throwing_copy_assignment); + } + + { + outcome_type outcome {}; + O o = make(S::zero); + VERIFY( o ); + O p = make(S::throwing_move_assignment); + + try + { + o = std::move(p); + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( o && o->state == S::threw); + VERIFY( p && p->state == S::moved_from); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/3.cc new file mode 100644 index 000000000..35d45bbb0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/3.cc @@ -0,0 +1,158 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct exception {}; + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter +{ + enum state_type + { + zero, + moved_from, + throwing_construction, + throwing_copy, + throwing_copy_assignment, + throwing_move, + throwing_move_assignment, + threw, + }; + + value_type() = default; + + explicit value_type(state_type state_) + : state(state_) + { + throw_if(throwing_construction); + } + + value_type(value_type const& other) + : state(other.state) + { + throw_if(throwing_copy); + } + + value_type& + operator=(value_type const& other) + { + state = other.state; + throw_if(throwing_copy_assignment); + return *this; + } + + value_type(value_type&& other) + : state(other.state) + { + other.state = moved_from; + throw_if(throwing_move); + } + + value_type& + operator=(value_type&& other) + { + state = other.state; + other.state = moved_from; + throw_if(throwing_move_assignment); + return *this; + } + + void throw_if(state_type match) + { + if(state == match) + { + state = threw; + throw exception {}; + } + } + + state_type state = zero; +}; + +int main() +{ + using O = std::experimental::optional<value_type>; + using S = value_type::state_type; + auto const make = [](S s = S::zero) { return value_type { s }; }; + + enum outcome_type { nothrow, caught, bad_catch }; + + // Check value assignment for disengaged optional + + { + O o; + value_type v = make(S::throwing_copy_assignment); + o = v; + VERIFY( o && o->state == S::throwing_copy_assignment ); + } + + { + O o; + value_type v = make(S::throwing_move_assignment); + o = std::move(v); + VERIFY( o && o->state == S::throwing_move_assignment ); + } + + { + outcome_type outcome {}; + O o; + value_type v = make(S::throwing_copy); + + try + { + o = v; + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( !o ); + } + + { + outcome_type outcome {}; + O o; + value_type v = make(S::throwing_move); + + try + { + o = std::move(v); + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( !o ); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/4.cc new file mode 100644 index 000000000..8aec8ab0a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/4.cc @@ -0,0 +1,158 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct exception {}; + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter +{ + enum state_type + { + zero, + moved_from, + throwing_construction, + throwing_copy, + throwing_copy_assignment, + throwing_move, + throwing_move_assignment, + threw, + }; + + value_type() = default; + + explicit value_type(state_type state_) + : state(state_) + { + throw_if(throwing_construction); + } + + value_type(value_type const& other) + : state(other.state) + { + throw_if(throwing_copy); + } + + value_type& + operator=(value_type const& other) + { + state = other.state; + throw_if(throwing_copy_assignment); + return *this; + } + + value_type(value_type&& other) + : state(other.state) + { + other.state = moved_from; + throw_if(throwing_move); + } + + value_type& + operator=(value_type&& other) + { + state = other.state; + other.state = moved_from; + throw_if(throwing_move_assignment); + return *this; + } + + void throw_if(state_type match) + { + if(state == match) + { + state = threw; + throw exception {}; + } + } + + state_type state = zero; +}; + +int main() +{ + using O = std::experimental::optional<value_type>; + using S = value_type::state_type; + auto const make = [](S s = S::zero) { return value_type { s }; }; + + enum outcome_type { nothrow, caught, bad_catch }; + + // Check value assignment for engaged optional + + { + O o = make(); + value_type v = make(S::throwing_copy); + o = v; + VERIFY( o && o->state == S::throwing_copy); + } + + { + O o = make(); + value_type v = make(S::throwing_move); + o = std::move(v); + VERIFY( o && o->state == S::throwing_move); + } + + { + outcome_type outcome {}; + O o = make(); + value_type v = make(S::throwing_copy_assignment); + + try + { + o = v; + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( o && o->state == S::threw ); + } + + { + outcome_type outcome {}; + O o = make(); + value_type v = make(S::throwing_move_assignment); + + try + { + o = std::move(v); + } + catch(exception const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( o && o->state == S::threw ); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc new file mode 100644 index 000000000..b7dff41c9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/5.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter { }; + +int main() +{ + using O = std::experimental::optional<value_type>; + + // Check std::experimental::nullopt_t and 'default' (= {}) assignment + + { + O o; + o = std::experimental::nullopt; + VERIFY( !o ); + } + + { + O o { std::experimental::in_place }; + o = std::experimental::nullopt; + VERIFY( !o ); + } + + { + O o; + o = {}; + VERIFY( !o ); + } + + { + O o { std::experimental::in_place }; + o = {}; + VERIFY( !o ); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/6.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/6.cc new file mode 100644 index 000000000..6418ab4aa --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/assignment/6.cc @@ -0,0 +1,83 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +struct value_type : private mixin_counter +{ + value_type() = default; + value_type(int) : state(1) { } + value_type(std::initializer_list<char>, const char*) : state(2) { } + int state = 0; +}; + +int main() +{ + using O = std::experimental::optional<value_type>; + + // Check emplace + + { + O o; + o.emplace(); + VERIFY( o && o->state == 0 ); + } + { + O o { std::experimental::in_place, 0 }; + o.emplace(); + VERIFY( o && o->state == 0 ); + } + + { + O o; + o.emplace(0); + VERIFY( o && o->state == 1 ); + } + { + O o { std::experimental::in_place }; + o.emplace(0); + VERIFY( o && o->state == 1 ); + } + + { + O o; + o.emplace({ 'a' }, ""); + VERIFY( o && o->state == 2 ); + } + { + O o { std::experimental::in_place }; + o.emplace({ 'a' }, ""); + VERIFY( o && o->state == 2 ); + } + + static_assert( !std::is_constructible<O, std::initializer_list<int>, int>(), "" ); + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/copy.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/copy.cc new file mode 100644 index 000000000..cd20634d1 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/copy.cc @@ -0,0 +1,126 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct tracker +{ + tracker(int value) : value(value) { ++count; } + ~tracker() { --count; } + + tracker(tracker const& other) : value(other.value) { ++count; } + tracker(tracker&& other) : value(other.value) + { + other.value = -1; + ++count; + } + + tracker& operator=(tracker const&) = default; + tracker& operator=(tracker&&) = default; + + int value; + + static int count; +}; + +int tracker::count = 0; + +struct exception { }; + +struct throwing_copy +{ + throwing_copy() = default; + throwing_copy(throwing_copy const&) { throw exception {}; } +}; + +int main() +{ + // [20.5.4.1] Constructors + + { + std::experimental::optional<long> o; + auto copy = o; + VERIFY( !copy ); + VERIFY( !o ); + } + + { + const long val = 0x1234ABCD; + std::experimental::optional<long> o { std::experimental::in_place, val}; + auto copy = o; + VERIFY( copy ); + VERIFY( *copy == val ); + VERIFY( o && o == val ); + } + + { + std::experimental::optional<tracker> o; + auto copy = o; + VERIFY( !copy ); + VERIFY( tracker::count == 0 ); + VERIFY( !o ); + } + + { + std::experimental::optional<tracker> o { std::experimental::in_place, 333 }; + auto copy = o; + VERIFY( copy ); + VERIFY( copy->value == 333 ); + VERIFY( tracker::count == 2 ); + VERIFY( o && o->value == 333 ); + } + + enum outcome { nothrow, caught, bad_catch }; + + { + outcome result = nothrow; + std::experimental::optional<throwing_copy> o; + + try + { + auto copy = o; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == nothrow ); + } + + { + outcome result = nothrow; + std::experimental::optional<throwing_copy> o { std::experimental::in_place }; + + try + { + auto copy = o; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == caught ); + } + + VERIFY( tracker::count == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/default.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/default.cc new file mode 100644 index 000000000..2d118e361 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/default.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct tracker +{ + tracker() { ++count; } + ~tracker() { --count; } + + tracker(tracker const&) { ++count; } + tracker(tracker&&) { ++count; } + + tracker& operator=(tracker const&) = default; + tracker& operator=(tracker&&) = default; + + static int count; +}; + +int tracker::count = 0; + +int main() +{ + // [20.5.4.1] Constructors + + { + std::experimental::optional<tracker> o; + VERIFY( !o ); + } + + { + std::experimental::optional<tracker> o {}; + VERIFY( !o ); + } + + { + std::experimental::optional<tracker> o = {}; + VERIFY( !o ); + } + + VERIFY( tracker::count == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/move.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/move.cc new file mode 100644 index 000000000..604bb58eb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/move.cc @@ -0,0 +1,126 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct tracker +{ + tracker(int value) : value(value) { ++count; } + ~tracker() { --count; } + + tracker(tracker const& other) : value(other.value) { ++count; } + tracker(tracker&& other) : value(other.value) + { + other.value = -1; + ++count; + } + + tracker& operator=(tracker const&) = default; + tracker& operator=(tracker&&) = default; + + int value; + + static int count; +}; + +int tracker::count = 0; + +struct exception { }; + +struct throwing_move +{ + throwing_move() = default; + throwing_move(throwing_move const&) { throw exception {}; } +}; + +int main() +{ + // [20.5.4.1] Constructors + + { + std::experimental::optional<long> o; + auto moved_to = std::move(o); + VERIFY( !moved_to ); + VERIFY( !o ); + } + + { + const long val = 0x1234ABCD; + std::experimental::optional<long> o { std::experimental::in_place, val}; + auto moved_to = std::move(o); + VERIFY( moved_to ); + VERIFY( *moved_to == val ); + VERIFY( o && *o == val ); + } + + { + std::experimental::optional<tracker> o; + auto moved_to = std::move(o); + VERIFY( !moved_to ); + VERIFY( tracker::count == 0 ); + VERIFY( !o ); + } + + { + std::experimental::optional<tracker> o { std::experimental::in_place, 333 }; + auto moved_to = std::move(o); + VERIFY( moved_to ); + VERIFY( moved_to->value == 333 ); + VERIFY( tracker::count == 2 ); + VERIFY( o && o->value == -1 ); + } + + enum outcome { nothrow, caught, bad_catch }; + + { + outcome result = nothrow; + std::experimental::optional<throwing_move> o; + + try + { + auto moved_to = std::move(o); + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == nothrow ); + } + + { + outcome result = nothrow; + std::experimental::optional<throwing_move> o { std::experimental::in_place }; + + try + { + auto moved_to = std::move(o); + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == caught ); + } + + VERIFY( tracker::count == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/value.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/value.cc new file mode 100644 index 000000000..68b088862 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/cons/value.cc @@ -0,0 +1,239 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <vector> + +struct tracker +{ + tracker(int value) : value(value) { ++count; } + ~tracker() { --count; } + + tracker(tracker const& other) : value(other.value) { ++count; } + tracker(tracker&& other) : value(other.value) + { + other.value = -1; + ++count; + } + + tracker& operator=(tracker const&) = default; + tracker& operator=(tracker&&) = default; + + int value; + + static int count; +}; + +int tracker::count = 0; + +struct exception { }; + +struct throwing_construction +{ + explicit throwing_construction(bool propagate) : propagate(propagate) { } + + throwing_construction(throwing_construction const& other) + : propagate(other.propagate) + { + if(propagate) + throw exception {}; + } + + bool propagate; +}; + +int main() +{ + // [20.5.4.1] Constructors + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o { i }; + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o = i; + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o = { i }; + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o { std::move(i) }; + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o = std::move(i); + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + auto i = 0x1234ABCD; + std::experimental::optional<long> o = { std::move(i) }; + VERIFY( o ); + VERIFY( *o == 0x1234ABCD ); + VERIFY( i == 0x1234ABCD ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o { v }; + VERIFY( !v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o = v; + VERIFY( !v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o { v }; + VERIFY( !v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o { std::move(v) }; + VERIFY( v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o = std::move(v); + VERIFY( v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + std::vector<int> v = { 0, 1, 2, 3, 4, 5 }; + std::experimental::optional<std::vector<int>> o { std::move(v) }; + VERIFY( v.empty() ); + VERIFY( o->size() == 6 ); + } + + { + tracker t { 333 }; + std::experimental::optional<tracker> o = t; + VERIFY( o->value == 333 ); + VERIFY( tracker::count == 2 ); + VERIFY( t.value == 333 ); + } + + { + tracker t { 333 }; + std::experimental::optional<tracker> o = std::move(t); + VERIFY( o->value == 333 ); + VERIFY( tracker::count == 2 ); + VERIFY( t.value == -1 ); + } + + enum outcome { nothrow, caught, bad_catch }; + + { + outcome result = nothrow; + throwing_construction t { false }; + + try + { + std::experimental::optional<throwing_construction> o { t }; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == nothrow ); + } + + { + outcome result = nothrow; + throwing_construction t { true }; + + try + { + std::experimental::optional<throwing_construction> o { t }; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == caught ); + } + + { + outcome result = nothrow; + throwing_construction t { false }; + + try + { + std::experimental::optional<throwing_construction> o { std::move(t) }; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == nothrow ); + } + + { + outcome result = nothrow; + throwing_construction t { true }; + + try + { + std::experimental::optional<throwing_construction> o { std::move(t) }; + } + catch(exception const&) + { result = caught; } + catch(...) + { result = bad_catch; } + + VERIFY( result == caught ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/default.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/default.cc new file mode 100644 index 000000000..dbad2ae65 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/default.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + // [20.5.4.1] Constructors + + { + constexpr std::experimental::optional<int> o; + static_assert( !o, "" ); + } + + { + constexpr std::experimental::optional<int> o {}; + static_assert( !o, "" ); + } + + { + constexpr std::experimental::optional<int> o = {}; + static_assert( !o, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/value.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/value.cc new file mode 100644 index 000000000..ade20b744 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/cons/value.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + // [20.5.4.1] Constructors + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o { i }; + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o = i; + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o = { i }; + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o { std::move(i) }; + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o = std::move(i); + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } + + { + constexpr long i = 0x1234ABCD; + constexpr std::experimental::optional<long> o = { std::move(i) }; + static_assert( o, "" ); + static_assert( *o == 0x1234ABCD, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/in_place.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/in_place.cc new file mode 100644 index 000000000..05313f9e8 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/in_place.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + // [20.5.5] In-place construction + static_assert( std::is_same<decltype(std::experimental::in_place), const std::experimental::in_place_t>(), "" ); + static_assert( std::is_empty<std::experimental::in_place_t>(), "" ); + + { + constexpr std::experimental::optional<int> o { std::experimental::in_place }; + static_assert( o, "" ); + static_assert( *o == int {}, "" ); + + static_assert( !std::is_convertible<std::experimental::in_place_t, std::experimental::optional<int>>(), "" ); + } + + { + constexpr std::experimental::optional<int> o { std::experimental::in_place, 42 }; + static_assert( o, "" ); + static_assert( *o == 42, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/make_optional.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/make_optional.cc new file mode 100644 index 000000000..fc45e2cbf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/make_optional.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++1y" } +// XFAIL pending resolution of PR libstdc++/58777 +// { dg-do compile { xfail *-*-* } } +// { dg-excess-errors "" } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + constexpr int i = 42; + constexpr auto o = std::experimental::make_optional(i); + static_assert( std::is_same<decltype(o), const std::experimental::optional<int>>(), "" ); + static_assert( o && *o == 42, "" ); + static_assert( &*o != &i, "" ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/nullopt.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/nullopt.cc new file mode 100644 index 000000000..6cd50dd82 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/nullopt.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + // [20.5.6] Disengaged state indicator + static_assert( std::is_same<decltype(std::experimental::nullopt), const std::experimental::nullopt_t>(), "" ); + static_assert( std::is_empty<std::experimental::nullopt_t>(), "" ); + static_assert( std::is_literal_type<std::experimental::nullopt_t>(), "" ); + static_assert( !std::is_default_constructible<std::experimental::nullopt_t>(), "" ); + + { + constexpr std::experimental::optional<int> o = std::experimental::nullopt; + static_assert( !o, "" ); + } + + { + constexpr std::experimental::optional<int> o = { std::experimental::nullopt }; + static_assert( !o, "" ); + } + + { + constexpr std::experimental::optional<int> o { std::experimental::nullopt }; + static_assert( !o, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/1.cc new file mode 100644 index 000000000..5aa2975ee --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/1.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + constexpr std::experimental::optional<value_type> o { value_type { 51 } }; + static_assert( (*o).i == 51, "" ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc new file mode 100644 index 000000000..aa78d8add --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/2.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++1y" } +// XFAIL pending resolution of PR libstdc++/58777 +// { dg-do compile { xfail *-*-* } } +// { dg-excess-errors "" } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + constexpr std::experimental::optional<value_type> o { value_type { 51 } }; + static_assert( o->i == 51, "" ); + static_assert( o->i == (*o).i, "" ); + static_assert( &o->i == &(*o).i, "" ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc new file mode 100644 index 000000000..2fa84101d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/3.cc @@ -0,0 +1,37 @@ +// { dg-options "-std=gnu++1y" } +// XFAIL pending resolution of PR libstdc++/58777 +// { dg-do compile { xfail *-*-* } } +// { dg-excess-errors "" } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + constexpr std::experimental::optional<value_type> o { value_type { 51 } }; + static_assert( o.value().i == 51, "" ); + static_assert( o.value().i == (*o).i, "" ); + static_assert( &o.value().i == &(*o).i, "" ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/4.cc new file mode 100644 index 000000000..b40659e0c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/4.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + constexpr std::experimental::optional<value_type> o { value_type { 51 } }; + constexpr value_type fallback { 3 }; + static_assert( o.value_or(fallback).i == 51, "" ); + static_assert( o.value_or(fallback).i == (*o).i, "" ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/5.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/5.cc new file mode 100644 index 000000000..4214d76db --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/observers/5.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + { + constexpr std::experimental::optional<value_type> o = std::experimental::nullopt; + static_assert( !o, "" ); + } + + { + constexpr std::experimental::optional<value_type> o { value_type { 51 } }; + static_assert( o, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc new file mode 100644 index 000000000..d38a97ce4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/1.cc @@ -0,0 +1,99 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + { + constexpr O o, p; + static_assert( o == p, "" ); + static_assert( !(o != p), "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p; + static_assert( !(o == p), "" ); + static_assert( o != p, "" ); + } + + { + constexpr O o, p { value_type { 42, "forty-two" } }; + static_assert( !(o == p), "" ); + static_assert( o != p, "" ); + } + + { + constexpr O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } }; + static_assert( !(o == p), "" ); + static_assert( o != p, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } }; + static_assert( !(o == p), "" ); + static_assert( o != p, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } }; + static_assert( o == p, "" ); + static_assert( !(o != p), "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc new file mode 100644 index 000000000..96da1b450 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/2.cc @@ -0,0 +1,111 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + { + constexpr O o, p; + static_assert( !(o < p), "" ); + static_assert( !(o > p), "" ); + static_assert( o <= p, "" ); + static_assert( o >= p, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p; + static_assert( !(o < p), "" ); + static_assert( o > p, "" ); + static_assert( !(o <= p), "" ); + static_assert( o >= p, "" ); + } + + { + constexpr O o, p { value_type { 42, "forty-two" } }; + static_assert( o < p, "" ); + static_assert( !(o > p), "" ); + static_assert( o <= p, "" ); + static_assert( !(o >= p), "" ); + } + + { + constexpr O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } }; + static_assert( o < p, "" ); + static_assert( !(o > p), "" ); + static_assert( o <= p, "" ); + static_assert( !(o >= p), "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } }; + static_assert( !(o < p), "" ); + static_assert( o > p, "" ); + static_assert( !(o <= p), "" ); + static_assert( o >= p, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } }; + static_assert( !(o < p), "" ); + static_assert( !(o > p), "" ); + static_assert( o <= p, "" ); + static_assert( o >= p, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc new file mode 100644 index 000000000..b57938d52 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/3.cc @@ -0,0 +1,89 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + constexpr value_type reference { 42, "forty-two" }; + + { + constexpr O o; + static_assert( !(o == reference), "" ); + static_assert( !(reference == o), "" ); + static_assert( o != reference, "" ); + static_assert( reference != o, "" ); + } + + { + constexpr O o { value_type { 11, "eleventy" } }; + static_assert( !(o == reference), "" ); + static_assert( !(reference == o), "" ); + static_assert( o != reference, "" ); + static_assert( reference != o, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }; + static_assert( o == reference, "" ); + static_assert( reference == o, "" ); + static_assert( !(o != reference), "" ); + static_assert( !(reference != o), "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc new file mode 100644 index 000000000..67a5cd40c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/4.cc @@ -0,0 +1,101 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + constexpr value_type reference { 42, "forty-two" }; + + { + constexpr O o; + static_assert( o < reference, "" ); + static_assert( !(reference < o), "" ); + static_assert( !(o > reference), "" ); + static_assert( reference > o, "" ); + static_assert( o <= reference, "" ); + static_assert( !(reference <= o), "" ); + static_assert( !(o >= reference), "" ); + static_assert( reference >= o, "" ); + } + + { + constexpr O o { value_type { 11, "eleventy" } }; + static_assert( o < reference, "" ); + static_assert( !(reference < o), "" ); + static_assert( !(o > reference), "" ); + static_assert( reference > o, "" ); + static_assert( o <= reference, "" ); + static_assert( !(reference <= o), "" ); + static_assert( !(o >= reference), "" ); + static_assert( reference >= o, "" ); + } + + { + constexpr O o { value_type { 42, "forty-two" } }; + static_assert( !(o < reference), "" ); + static_assert( !(reference < o), "" ); + static_assert( !(o > reference), "" ); + static_assert( !(reference > o), "" ); + static_assert( o <= reference, "" ); + static_assert( reference <= o, "" ); + static_assert( o >= reference, "" ); + static_assert( reference >= o, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc new file mode 100644 index 000000000..56742d2df --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/5.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + using std::experimental::nullopt; + + { + constexpr O o; + static_assert( o == nullopt, "" ); + static_assert( nullopt == o, "" ); + static_assert( !(o != nullopt), "" ); + static_assert( !(nullopt != o), "" ); + } + + { + constexpr O o { std::experimental::in_place }; + static_assert( !(o == nullopt), "" ); + static_assert( !(nullopt == o), "" ); + static_assert( o != nullopt, "" ); + static_assert( nullopt != o, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc new file mode 100644 index 000000000..b47cb61b2 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/constexpr/relops/6.cc @@ -0,0 +1,88 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +namespace ns +{ + struct value_type + { + int i; + const char* s; + }; + + constexpr bool + strcmp(const char* lhs, const char* rhs) + { + return *lhs == *rhs && (!*lhs || strcmp(lhs + 1, rhs + 1)); + } + + constexpr bool + strrel(const char* lhs, const char* rhs) + { + return (*rhs && (!*lhs || (*lhs < *rhs))) + || ((*lhs && *rhs && !(*rhs < *lhs)) && strrel(lhs + 1, rhs + 1)); + } + + constexpr bool + operator==(value_type const& lhs, value_type const& rhs) + { return (lhs.i == rhs.i) && strcmp(lhs.s, rhs.s); } + + constexpr bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + constexpr bool + operator<(value_type const& lhs, value_type const& rhs) + { return (lhs.i < rhs.i) || (!(rhs.i < lhs.i) && strrel(lhs.s, rhs.s)); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + using std::experimental::nullopt; + + { + constexpr O o; + static_assert( !(o < nullopt), "" ); + static_assert( !(nullopt < o), "" ); + static_assert( !(o > nullopt), "" ); + static_assert( !(nullopt > o), "" ); + static_assert( o <= nullopt, "" ); + static_assert( nullopt <= o, "" ); + static_assert( o >= nullopt, "" ); + static_assert( nullopt >= o, "" ); + } + + { + constexpr O o { std::experimental::in_place }; + static_assert( !(o < nullopt), "" ); + static_assert( nullopt < o, "" ); + static_assert( o > nullopt, "" ); + static_assert( !(nullopt > o), "" ); + static_assert( !(o <= nullopt), "" ); + static_assert( nullopt <= o, "" ); + static_assert( o >= nullopt, "" ); + static_assert( !(nullopt >= o), "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/in_place.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/in_place.cc new file mode 100644 index 000000000..66525b27a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/in_place.cc @@ -0,0 +1,66 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <vector> + +int main() +{ + // [20.5.5] In-place construction + static_assert( std::is_same<decltype(std::experimental::in_place), const std::experimental::in_place_t>(), "" ); + static_assert( std::is_empty<std::experimental::in_place_t>(), "" ); + + { + std::experimental::optional<int> o { std::experimental::in_place }; + VERIFY( o ); + VERIFY( *o == int() ); + + static_assert( !std::is_convertible<std::experimental::in_place_t, std::experimental::optional<int>>(), "" ); + } + + { + std::experimental::optional<int> o { std::experimental::in_place, 42 }; + VERIFY( o ); + VERIFY( *o == 42 ); + } + + { + std::experimental::optional<std::vector<int>> o { std::experimental::in_place, 18, 4 }; + VERIFY( o ); + VERIFY( o->size() == 18 ); + VERIFY( (*o)[17] == 4 ); + } + + { + std::experimental::optional<std::vector<int>> o { std::experimental::in_place, { 18, 4 } }; + VERIFY( o ); + VERIFY( o->size() == 2 ); + VERIFY( (*o)[0] == 18 ); + } + + { + std::experimental::optional<std::vector<int>> o { std::experimental::in_place, { 18, 4 }, std::allocator<int> {} }; + VERIFY( o ); + VERIFY( o->size() == 2 ); + VERIFY( (*o)[0] == 18 ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/make_optional.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/make_optional.cc new file mode 100644 index 000000000..99122c018 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/make_optional.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + const int i = 42; + auto o = std::experimental::make_optional(i); + static_assert( std::is_same<decltype(o), std::experimental::optional<int>>(), "" ); + VERIFY( o && *o == 42 ); + VERIFY( &*o != &i ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/nullopt.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/nullopt.cc new file mode 100644 index 000000000..560579791 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/nullopt.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +int main() +{ + // [20.5.6] Disengaged state indicator + static_assert( std::is_same<decltype(std::experimental::nullopt), const std::experimental::nullopt_t>(), "" ); + static_assert( std::is_empty<std::experimental::nullopt_t>(), "" ); + static_assert( std::is_literal_type<std::experimental::nullopt_t>(), "" ); + static_assert( !std::is_default_constructible<std::experimental::nullopt_t>(), "" ); + + { + std::experimental::optional<int> o = std::experimental::nullopt; + VERIFY( !o ); + } + + { + std::experimental::optional<int> o = { std::experimental::nullopt }; + VERIFY( !o ); + } + + { + std::experimental::optional<int> o { std::experimental::nullopt }; + VERIFY( !o ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/1.cc new file mode 100644 index 000000000..0316df6ed --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/1.cc @@ -0,0 +1,33 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + std::experimental::optional<value_type> o { value_type { 51 } }; + VERIFY( (*o).i == 51 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/2.cc new file mode 100644 index 000000000..924ed095d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/2.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + std::experimental::optional<value_type> o { value_type { 51 } }; + VERIFY( o->i == 51 ); + VERIFY( o->i == (*o).i ); + VERIFY( &o->i == &(*o).i ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/3.cc new file mode 100644 index 000000000..bdaf6cbba --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/3.cc @@ -0,0 +1,58 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + { + std::experimental::optional<value_type> o { value_type { 51 } }; + VERIFY( o.value().i == 51 ); + VERIFY( o.value().i == (*o).i ); + VERIFY( &o.value().i == &(*o).i ); + } + + { + enum outcome_type { nothrow, caught, bad_catch }; + + outcome_type outcome {}; + std::experimental::optional<value_type> o = std::experimental::nullopt; + bool called = false; + auto const eat = [&called](int) { called = true; }; + + try + { + eat(o.value().i); + } + catch(std::experimental::bad_optional_access const&) + { outcome = caught; } + catch(...) + { outcome = bad_catch; } + + VERIFY( outcome == caught ); + VERIFY( !called ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/4.cc new file mode 100644 index 000000000..a738f121c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/4.cc @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + std::experimental::optional<value_type> o { value_type { 51 } }; + value_type fallback { 3 }; + VERIFY( o.value_or(fallback).i == 51 ); + VERIFY( o.value_or(fallback).i == (*o).i ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/5.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/5.cc new file mode 100644 index 000000000..c6a602282 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/observers/5.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct value_type +{ + int i; +}; + +int main() +{ + { + std::experimental::optional<value_type> o = std::experimental::nullopt; + VERIFY( !o ); + } + + { + std::experimental::optional<value_type> o { value_type { 51 } }; + VERIFY( o ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/1.cc new file mode 100644 index 000000000..f1408805a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/1.cc @@ -0,0 +1,89 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + { + O o, p; + VERIFY( o == p ); + VERIFY( !(o != p) ); + } + + { + O o { value_type { 42, "forty-two" } }, p; + VERIFY( !(o == p) ); + VERIFY( o != p ); + } + + { + O o, p { value_type { 42, "forty-two" } }; + VERIFY( !(o == p) ); + VERIFY( o != p ); + } + + { + O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } }; + VERIFY( !(o == p) ); + VERIFY( o != p ); + } + + { + O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } }; + VERIFY( !(o == p) ); + VERIFY( o != p ); + } + + { + O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } }; + VERIFY( o == p ); + VERIFY( !(o != p) ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/2.cc new file mode 100644 index 000000000..c7fc848de --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/2.cc @@ -0,0 +1,101 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + { + O o, p; + VERIFY( !(o < p) ); + VERIFY( !(o > p) ); + VERIFY( o <= p ); + VERIFY( o >= p ); + } + + { + O o { value_type { 42, "forty-two" } }, p; + VERIFY( !(o < p) ); + VERIFY( o > p ); + VERIFY( !(o <= p) ); + VERIFY( o >= p ); + } + + { + O o, p { value_type { 42, "forty-two" } }; + VERIFY( o < p ); + VERIFY( !(o > p) ); + VERIFY( o <= p ); + VERIFY( !(o >= p) ); + } + + { + O o { value_type { 11, "eleventy" } }, p { value_type { 42, "forty-two" } }; + VERIFY( o < p ); + VERIFY( !(o > p) ); + VERIFY( o <= p ); + VERIFY( !(o >= p) ); + } + + { + O o { value_type { 42, "forty-two" } }, p { value_type { 11, "eleventy" } }; + VERIFY( !(o < p) ); + VERIFY( o > p ); + VERIFY( !(o <= p) ); + VERIFY( o >= p ); + } + + { + O o { value_type { 42, "forty-two" } }, p { value_type { 42, "forty-two" } }; + VERIFY( !(o < p) ); + VERIFY( !(o > p) ); + VERIFY( o <= p ); + VERIFY( o >= p ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/3.cc new file mode 100644 index 000000000..9729000d5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/3.cc @@ -0,0 +1,79 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + value_type const reference { 42, "forty-two" }; + + { + O o; + VERIFY( !(o == reference) ); + VERIFY( !(reference == o) ); + VERIFY( o != reference ); + VERIFY( reference != o ); + } + + { + O o { value_type { 11, "eleventy" } }; + VERIFY( !(o == reference) ); + VERIFY( !(reference == o) ); + VERIFY( o != reference ); + VERIFY( reference != o ); + } + + { + O o { value_type { 42, "forty-two" } }; + VERIFY( o == reference ); + VERIFY( reference == o ); + VERIFY( !(o != reference) ); + VERIFY( !(reference != o) ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/4.cc new file mode 100644 index 000000000..45378f688 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/4.cc @@ -0,0 +1,91 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + + value_type const reference { 42, "forty-two" }; + + { + O o; + VERIFY( o < reference ); + VERIFY( !(reference < o) ); + VERIFY( !(o > reference) ); + VERIFY( reference > o ); + VERIFY( o <= reference ); + VERIFY( !(reference <= o) ); + VERIFY( !(o >= reference) ); + VERIFY( reference >= o ); + } + + { + O o { value_type { 11, "eleventy" } }; + VERIFY( o < reference ); + VERIFY( !(reference < o) ); + VERIFY( !(o > reference) ); + VERIFY( reference > o ); + VERIFY( o <= reference ); + VERIFY( !(reference <= o) ); + VERIFY( !(o >= reference) ); + VERIFY( reference >= o ); + } + + { + O o { value_type { 42, "forty-two" } }; + VERIFY( !(o < reference) ); + VERIFY( !(reference < o) ); + VERIFY( !(o > reference) ); + VERIFY( !(reference > o) ); + VERIFY( o <= reference ); + VERIFY( reference <= o ); + VERIFY( o >= reference ); + VERIFY( reference >= o ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/5.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/5.cc new file mode 100644 index 000000000..008409ef4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/5.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + using std::experimental::nullopt; + + { + O o; + VERIFY( o == nullopt ); + VERIFY( nullopt == o ); + VERIFY( !(o != nullopt) ); + VERIFY( !(nullopt != o) ); + } + + { + O o { std::experimental::in_place }; + VERIFY( !(o == nullopt) ); + VERIFY( !(nullopt == o) ); + VERIFY( o != nullopt ); + VERIFY( nullopt != o ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/6.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/6.cc new file mode 100644 index 000000000..b17914062 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/relops/6.cc @@ -0,0 +1,78 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> +#include <string> + +namespace ns +{ + struct value_type + { + int i; + std::string s; + }; + + bool + operator==(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) == std::tie(rhs.i, rhs.s); } + + bool + operator!=(value_type const& lhs, value_type const& rhs) + { return !(lhs == rhs); } + + bool + operator<(value_type const& lhs, value_type const& rhs) + { return std::tie(lhs.i, lhs.s) < std::tie(rhs.i, rhs.s); } + +} // namespace ns + +int main() +{ + using ns::value_type; + using O = std::experimental::optional<value_type>; + using std::experimental::nullopt; + + { + O o; + VERIFY( !(o < nullopt) ); + VERIFY( !(nullopt < o) ); + VERIFY( !(o > nullopt) ); + VERIFY( !(nullopt > o) ); + VERIFY( o <= nullopt ); + VERIFY( nullopt <= o ); + VERIFY( o >= nullopt ); + VERIFY( nullopt >= o ); + } + + { + O o { std::experimental::in_place }; + VERIFY( !(o < nullopt) ); + VERIFY( nullopt < o ); + VERIFY( o > nullopt ); + VERIFY( !(nullopt > o) ); + VERIFY( !(o <= nullopt) ); + VERIFY( nullopt <= o ); + VERIFY( o >= nullopt ); + VERIFY( !(nullopt >= o) ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/requirements.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/requirements.cc new file mode 100644 index 000000000..4b0535b47 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/requirements.cc @@ -0,0 +1,256 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +#include <tuple> + +struct trivially_destructible +{ + trivially_destructible() = delete; + trivially_destructible(trivially_destructible const&) = delete; + trivially_destructible& operator=(trivially_destructible const&) = delete; + trivially_destructible(trivially_destructible&&) = delete; + trivially_destructible& operator=(trivially_destructible&&) = delete; + ~trivially_destructible() noexcept = default; +}; + +static_assert( std::is_trivially_destructible<trivially_destructible>(), "" ); + +struct no_default_constructor +{ + no_default_constructor() = delete; +}; + +struct no_copy_constructor +{ + no_copy_constructor() = default; + no_copy_constructor(no_copy_constructor const&) = delete; + no_copy_constructor& operator=(no_copy_constructor const&) = default; + no_copy_constructor(no_copy_constructor&&) = default; + no_copy_constructor& operator=(no_copy_constructor&&) = default; +}; + +struct no_copy_assignment +{ + no_copy_assignment() = default; + no_copy_assignment(no_copy_assignment const&) = default; + no_copy_assignment(no_copy_assignment&&) = default; + no_copy_assignment& operator=(no_copy_assignment&&) = default; +}; + +struct no_move_constructor +{ + no_move_constructor() = default; + no_move_constructor(no_move_constructor const&) = default; + no_move_constructor& operator=(no_move_constructor const&) = default; + no_move_constructor(no_move_constructor&&) = delete; + no_move_constructor& operator=(no_move_constructor&&) = default; +}; + +struct no_move_assignment +{ + no_move_assignment() = default; + no_move_assignment(no_move_assignment const&) = default; + no_move_assignment& operator=(no_move_assignment const&) = default; + no_move_assignment(no_move_assignment&&) = default; + no_move_assignment& operator=(no_move_assignment&&) = delete; +}; + +struct no_copy : no_copy_constructor, no_copy_assignment { }; +struct no_move : no_move_constructor, no_move_assignment { }; + +// Laxest possible model of a value type for optional +struct only_destructible +{ + only_destructible(only_destructible&&) = delete; +}; + +int main() +{ + { + static_assert( std::is_trivially_destructible<std::experimental::optional<trivially_destructible>>(), "" ); + } + + { + using T = no_default_constructor; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( std::is_copy_constructible<O>(), "" ); + { O o; auto copy = o; } + static_assert( std::is_copy_assignable<O>(), "" ); + { O o, p; p = o; } + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_copy_constructor; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( !std::is_copy_constructible<O>(), "" ); + static_assert( !std::is_copy_assignable<O>(), "" ); + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_copy_assignment; + using O = std::experimental::optional<T>; + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( std::is_copy_constructible<O>(), "" ); + { O o; auto copy = o; } + static_assert( !std::is_copy_assignable<O>(), "" ); + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_copy; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( !std::is_copy_constructible<O>(), "" ); + static_assert( !std::is_copy_assignable<O>(), "" ); + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_move_constructor; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( std::is_copy_constructible<O>(), "" ); + { O o; auto copy = o; } + static_assert( std::is_copy_assignable<O>(), "" ); + /* + * T should be move constructible due to [12.8/11], which is a new rule in C++1y + * not yet implemented by GCC. Because there is already a special exception in C++11 + * for the generation of the special members that GCC implements (at least some of the + * time), this does not affect the std::experimental::optional implementation however. So the assertion + * for T should be changed (or removed altogether) when the time comes, but the rest + * should however remain correct and unchanged. + */ + static_assert( !std::is_move_constructible<T>(), "" ); + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_move_assignment; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( std::is_copy_constructible<O>(), "" ); + { O o; auto copy = o; } + static_assert( std::is_copy_assignable<O>(), "" ); + { O o, p; p = o; } + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + /* + * Paragraph 23 of same leads to a similar situation but with respect to move + * assignment. + */ + static_assert( !std::is_move_assignable<T>(), "" ); + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = no_move; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( std::is_copy_constructible<O>(), "" ); + { O o; auto copy = o; } + static_assert( std::is_copy_assignable<O>(), "" ); + { O o, p; p = o; } + static_assert( std::is_move_constructible<O>(), "" ); + { O o; auto moved_to = std::move(o); } + static_assert( std::is_move_assignable<O>(), "" ); + { O o, p; p = std::move(o); } + } + + { + using T = only_destructible; + using O = std::experimental::optional<T>; + static_assert( std::is_same<O::value_type, T>(), "" ); + static_assert( std::is_default_constructible<O>(), "" ); + { O o; } + static_assert( !std::is_copy_constructible<O>(), "" ); + static_assert( !std::is_copy_assignable<O>(), "" ); + static_assert( !std::is_move_constructible<O>(), "" ); + static_assert( !std::is_move_assignable<O>(), "" ); + } + + { + /* + * Should not complain about 'invalid' specializations as long as + * they're not instantiated. + */ + using A = std::experimental::optional<int&>; + using B = std::experimental::optional<int&&>; + using C1 = std::experimental::optional<std::experimental::in_place_t>; + using C2 = std::experimental::optional<std::experimental::in_place_t const>; + using C3 = std::experimental::optional<std::experimental::in_place_t volatile>; + using C4 = std::experimental::optional<std::experimental::in_place_t const volatile>; + using D1 = std::experimental::optional<std::experimental::nullopt_t>; + using D2 = std::experimental::optional<std::experimental::nullopt_t const>; + using D3 = std::experimental::optional<std::experimental::nullopt_t volatile>; + using D4 = std::experimental::optional<std::experimental::nullopt_t const volatile>; + + using X = std::tuple<A, B, C1, C2, C3, C4, D1, D2, D3, D4>; + } + + { + std::experimental::optional<const int> o { 42 }; + static_assert( std::is_same<decltype(o)::value_type, const int>(), "" ); + VERIFY( o ); + VERIFY( *o == 42 ); + } + + { + constexpr std::experimental::optional<const int> o { 33 }; + static_assert( std::is_same<decltype(o)::value_type, const int>(), "" ); + static_assert( o, "" ); + static_assert( *o == 33, "" ); + } +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/swap/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/swap/1.cc new file mode 100644 index 000000000..db754ce3e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/optional/swap/1.cc @@ -0,0 +1,95 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do run } + +// Copyright (C) 2013-2014 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 moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/optional> +#include <testsuite_hooks.h> + +struct exception {}; + +int counter = 0; + +struct mixin_counter +{ + mixin_counter() { ++counter; } + mixin_counter(mixin_counter const&) { ++counter; } + ~mixin_counter() { --counter; } +}; + +namespace ns +{ + +struct value_type : private mixin_counter +{ + explicit value_type(int state) : state(state) { } + int state; +}; + +int swaps = 0; + +void +swap(value_type& lhs, value_type& rhs) +{ + ++swaps; + using std::swap; + swap(lhs.state, rhs.state); +} + +} // namespace ns + +int main() +{ + using O = std::experimental::optional<ns::value_type>; + + VERIFY( ns::swaps == 0 ); + + { + O o, p; + swap(o, p); + VERIFY( !o ); + VERIFY( !p ); + } + + { + O o { std::experimental::in_place, 45 }, p; + swap(o, p); + VERIFY( !o ); + VERIFY( p && p->state == 45 ); + } + + { + O o, p { std::experimental::in_place, 45 }; + swap(o, p); + VERIFY( o && o->state == 45 ); + VERIFY( !p ); + } + + { + O o { std::experimental::in_place, 167 }, p { std::experimental::in_place, 999 }; + VERIFY( ns::swaps == 0 ); + + swap(o, p); + + VERIFY( o && o->state == 999 ); + VERIFY( p && p->state == 167 ); + VERIFY( ns::swaps == 1 ); + } + + VERIFY( counter == 0 ); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/capacity/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/capacity/1.cc new file mode 100644 index 000000000..ff9df9a08 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/capacity/1.cc @@ -0,0 +1,164 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// string_view size, length + +#include <experimental/string_view> +#include <cstring> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +template<typename T> + bool + operator==(const A<T>&, const A<T>&) { return true; } + +template<typename T> + bool + operator<(const A<T>&, const A<T>&) { return true; } + +struct B { }; + +// char_traits specialization +namespace std +{ + template<> + struct char_traits<A<B> > + { + typedef A<B> char_type; + // Unsigned as wint_t in unsigned. + typedef unsigned long int_type; + typedef streampos pos_type; + typedef streamoff off_type; + typedef mbstate_t state_type; + + static void + assign(char_type& __c1, const char_type& __c2) + { __c1 = __c2; } + + static bool + eq(const char_type& __c1, const char_type& __c2) + { return __c1 == __c2; } + + static bool + lt(const char_type& __c1, const char_type& __c2) + { return __c1 < __c2; } + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n) + { + for (size_t __i = 0; __i < __n; ++__i) + if (!eq(__s1[__i], __s2[__i])) + return lt(__s1[__i], __s2[__i]) ? -1 : 1; + return 0; + } + + static size_t + length(const char_type* __s) + { + const char_type* __p = __s; + while (__p) + ++__p; + return (__p - __s); + } + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a) + { + for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) + if (*__p == __a) return __p; + return 0; + } + + static char_type* + move(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + assign(char_type* __s, size_t __n, char_type __a) + { + for (char_type* __p = __s; __p < __s + __n; ++__p) + assign(*__p, __a); + return __s; + } + + static char_type + to_char_type(const int_type&) + { return char_type(); } + + static int_type + to_int_type(const char_type&) { return int_type(); } + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2) + { return __c1 == __c2; } + + static int_type + eof() { return static_cast<int_type>(-1); } + + static int_type + not_eof(const int_type& __c) + { return eq_int_type(__c, eof()) ? int_type(0) : __c; } + }; +} // namespace std + +void +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::basic_string_view<A<B>> str02; + typedef std::experimental::basic_string_view< A<B> >::size_type size_type_o; + size_type_o sz03; + size_type_o sz04; + + // non-POD types: size, length, max_size, clear(), empty() + bool b01 = str02.empty(); + VERIFY( b01 == true ); + sz03 = str02.size(); + sz04 = str02.length(); + VERIFY( sz03 == sz04 ); + str02.data(); + sz03 = str02.size(); + sz04 = str02.length(); + VERIFY( sz03 == sz04 ); + + sz03 = str02.max_size(); + VERIFY( sz03 >= sz04 ); + + sz03 = str02.size(); + str02.clear(); + b01 = str02.empty(); + VERIFY( b01 == true ); + sz04 = str02.size(); + VERIFY( sz03 >= sz04 ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc new file mode 100644 index 000000000..c879cc7e0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/1.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <experimental/string_view> +#include <string> +#include <cstring> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + typedef std::experimental::string_view::size_type csize_type; + + // basic_string_view() + const std::experimental::string_view str00{}; + VERIFY( str00.length() == 0 ); + VERIFY( str00.data() != nullptr ); + + // basic_string_view(const char*) + const char str_lit01[] = "rodeo beach, marin"; + const std::experimental::string_view str01{str_lit01}; + VERIFY( str01.length() == 18 ); + VERIFY( str01.data() == str_lit01 ); + const std::experimental::string_view str02{"baker beach, san francisco"}; + VERIFY( str02.length() == 26 ); + + // basic_string_view(const string_view&) + std::experimental::string_view str04{str01}; + VERIFY( str04.length() == str01.length() ); + VERIFY( str04.data() == str01.data() ); + + // basic_string_view(const char* s) + csize_type len_lit01 = strlen(str_lit01); + std::experimental::string_view str05{str_lit01, len_lit01}; + VERIFY( str05.length() == len_lit01 ); + VERIFY( str05.data() == str_lit01 ); + + // basic_string_view(const char* s, std::size_t l) + std::experimental::string_view str06{nullptr, len_lit01}; + VERIFY( str06.length() == 0 ); + VERIFY( str06.data() != nullptr ); + + // basic_string_view(basic_string& s) + std::string istr07(10, 'z'); + std::experimental::string_view str07{istr07}; + VERIFY( str07.length() == 10 ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/2.cc new file mode 100644 index 000000000..b58dfb561 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/2.cc @@ -0,0 +1,48 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <new> +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +void +test03() +{ + bool test [[gnu::unused]] = true; + const char* with_nulls = "This contains \0 a zero byte."; + + // These are tests to see how basic_string_view handles data with NUL + // bytes. Obviously basic_string_view(char*) will halt at the first one, but + // nothing else should. + std::experimental::string_view s1(with_nulls, 28); + VERIFY( s1.size() == 28 ); + std::experimental::string_view s2(s1); + VERIFY( s2.size() == 28 ); +} + +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/3.cc new file mode 100644 index 000000000..fdb37d51e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/char/3.cc @@ -0,0 +1,41 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <experimental/string_view> +#include <vector> +#include <testsuite_hooks.h> + +void +test05() +{ + bool test [[gnu::unused]] = true; + + char const * s = 0; + std::experimental::string_view zero_length_built_with_NULL(s, 0); +} + +int +main() +{ + test05(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc new file mode 100644 index 000000000..12db72f28 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/1.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <experimental/string_view> +#include <string> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + typedef std::experimental::wstring_view::size_type csize_type; + + // basic_string_view() + const std::experimental::wstring_view str00{}; + VERIFY( str00.length() == 0 ); + VERIFY( str00.data() != nullptr ); + + // basic_string_view(const char*) + const wchar_t str_lit01[] = L"rodeo beach, marin"; + const std::experimental::wstring_view str01{str_lit01}; + VERIFY( str01.length() == 18 ); + VERIFY( str01.data() == str_lit01 ); + const std::experimental::wstring_view str02{L"baker beach, san francisco"}; + VERIFY( str02.length() == 26 ); + + // basic_string_view(const string_view&) + std::experimental::wstring_view str04{str01}; + VERIFY( str04.length() == str01.length() ); + VERIFY( str04.data() == str01.data() ); + + // basic_string_view(const char* s) + csize_type len_lit01 = wcslen(str_lit01); + std::experimental::wstring_view str05{str_lit01, len_lit01}; + VERIFY( str05.length() == len_lit01 ); + VERIFY( str05.data() == str_lit01 ); + + // basic_string_view(const wchar_t* s, std::size_t l) + std::experimental::wstring_view str06{nullptr, len_lit01}; + VERIFY( str06.length() == 0 ); + VERIFY( str06.data() != nullptr ); + + // basic_string_view(basic_string& s) + std::wstring istr07(10, L'z'); + std::experimental::wstring_view str07{istr07}; + VERIFY( str07.length() == 10 ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/2.cc new file mode 100644 index 000000000..1d73f2f12 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/2.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test03() +{ + bool test [[gnu::unused]] = true; + const wchar_t* with_nulls = L"This contains \0 a zero byte."; + + // These are tests to see how basic_string_view handles data with NUL + // bytes. Obviously basic_string_view(char*) will halt at the first one, but + // nothing else should. + std::experimental::wstring_view s1 (with_nulls, 28); + VERIFY( s1.size() == 28 ); + std::experimental::wstring_view s2 (s1); + VERIFY( s2.size() == 28 ); +} + +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/3.cc new file mode 100644 index 000000000..76a1e9436 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/cons/wchar_t/3.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view constructors. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test05() +{ + bool test [[gnu::unused]] = true; + + wchar_t const * s = 0; + std::experimental::wstring_view zero_length_built_with_NULL(s, 0); +} + +int +main() +{ + test05(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/1.cc new file mode 100644 index 000000000..0a0b19f60 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/1.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string element access + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + typedef std::experimental::string_view::const_reference cref; + typedef std::experimental::string_view::reference ref; + csize_type csz01, csz02; + + const std::experimental::string_view str01("tamarindo, costa rica"); + std::experimental::string_view str02("41st street beach, capitola, california"); + std::experimental::string_view str03; + + // const_reference operator[] (size_type pos) const; + csz01 = str01.size(); + cref cref1 = str01[csz01 - 1]; + VERIFY( cref1 == 'a' ); + // Undefined behavior at size(). + //cref cref2 = str01[csz01]; + //VERIFY( cref2 == char() ); + + // const_reference at(size_type pos) const; + csz01 = str01.size(); + cref cref3 = str01.at(csz01 - 1); + VERIFY( cref3 == 'a' ); + try + { + str01.at(csz01); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch (std::out_of_range& fail) + { + VERIFY( true ); + } + catch (...) + { + VERIFY( false ); + } + + return test; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/2.cc new file mode 100644 index 000000000..ef2fcc0e5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/2.cc @@ -0,0 +1,30 @@ +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=gnu++1y -O0" } +// { dg-require-debug-mode "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +int +main() +{ + typedef std::experimental::string_view string_view_type; + string_view_type s; + s[0]; // abort +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/empty.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/empty.cc new file mode 100644 index 000000000..17c983df3 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/empty.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 3 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/>. +// + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +main() +{ + bool test [[gnu::unused]] = true; + + { + std::experimental::string_view empty; + VERIFY( empty.empty() ); + } + + { + const std::experimental::string_view empty; + VERIFY( empty.empty() ); + } + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/front_back.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/front_back.cc new file mode 100644 index 000000000..92831fa9e --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/char/front_back.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } +// { dg-require-string-conversions "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::string_view str("ramifications"); + const std::experimental::string_view cstr("melodien"); + + VERIFY( str.front() == 'r' ); + VERIFY( str.back() == 's' ); + VERIFY( cstr.front() == 'm' ); + VERIFY( cstr.back() == 'n' ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/1.cc new file mode 100644 index 000000000..e3df84d41 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/1.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view element access + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + typedef std::experimental::wstring_view::const_reference cref; + typedef std::experimental::wstring_view::reference ref; + csize_type csz01, csz02; + + const std::experimental::wstring_view str01(L"tamarindo, costa rica"); + std::experimental::wstring_view str02(L"41st street beach, capitola, california"); + std::experimental::wstring_view str03; + + // const_reference operator[] (size_type pos) const; + csz01 = str01.size(); + cref cref1 = str01[csz01 - 1]; + VERIFY( cref1 == L'a' ); + // Undefined behavior at size(). + //cref cref2 = str01[csz01]; + //VERIFY( cref2 == wchar_t() ); + + // const_reference at(size_type pos) const; + csz01 = str01.size(); + cref cref3 = str01.at(csz01 - 1); + VERIFY( cref3 == L'a' ); + try + { + str01.at(csz01); + VERIFY( false ); // Should not get here, as exception thrown. + } + catch (std::out_of_range& fail) + { + VERIFY( true ); + } + catch (...) + { + VERIFY( false ); + } + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/2.cc new file mode 100644 index 000000000..4ffa7ddfe --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/2.cc @@ -0,0 +1,32 @@ +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=gnu++1y -O0" } +// { dg-require-debug-mode "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +// libstdc++/21674 +// NB: Should work without any inlining or optimizations (ie. -O0). +int +main() +{ + typedef std::experimental::wstring_view string_view_type; + string_view_type s; + s[0]; // abort +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/empty.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/empty.cc new file mode 100644 index 000000000..e7a265c9c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/empty.cc @@ -0,0 +1,40 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. +// + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +main() +{ + bool test [[gnu::unused]] = true; + + { + std::experimental::wstring_view empty; + VERIFY( empty.empty() ); + } + + { + const std::experimental::wstring_view empty; + VERIFY( empty.empty() ); + } + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/front_back.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/front_back.cc new file mode 100644 index 000000000..c119b36ce --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/element_access/wchar_t/front_back.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } +// { dg-require-string-conversions "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::wstring_view str(L"ramifications"); + const std::experimental::wstring_view cstr(L"melodien"); + + VERIFY( str.front() == L'r' ); + VERIFY( str.back() == L's' ); + VERIFY( cstr.front() == L'm' ); + VERIFY( cstr.back() == L'n' ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/include.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/include.cc new file mode 100644 index 000000000..4f7a8f20b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/include.cc @@ -0,0 +1,25 @@ +// -*- C++ -*- + +// Copyright (C) 2013-2014 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/>. + +// NB: This issue affected only debug-mode. + +// { dg-options "-std=gnu++1y -fno-rtti" } +// { dg-do compile } + +#include <experimental/string_view> diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/1.cc new file mode 100644 index 000000000..62f35ed34 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/1.cc @@ -0,0 +1,69 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +#include <experimental/string_view> +#include <stdexcept> +#include <sstream> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + typedef std::experimental::string_view::const_reference cref; + typedef std::experimental::string_view::reference ref; + + const std::experimental::string_view str01("sailing grand traverse bay\n" + "\t\t\t from Elk Rapids to the point reminds me of miles"); + + // ostream& operator<<(ostream&, const basic_string_view&) + std::ostringstream ostrs01; + try + { + ostrs01 << str01; + VERIFY( ostrs01.str() == str01 ); + } + catch(std::exception& fail) + { + VERIFY( false ); + } + + std::experimental::string_view hello_world; + std::cout << hello_world; + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/2.cc new file mode 100644 index 000000000..0379ed1bd --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/2.cc @@ -0,0 +1,93 @@ + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +// { dg-options "-std=gnu++1y" } +// { dg-require-fileio "" } + +#include <experimental/string_view> +#include <string> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +// testing basic_filebuf::xsputn via stress testing with large string_views +// based on a bug report libstdc++ 9 +// mode == out +void +test05(std::size_t size) +{ + bool test [[gnu::unused]] = true; + + const char filename[] = "inserters_extractors-2.txt"; + const char fillc = 'f'; + std::ofstream ofs(filename); + std::string str(size, fillc); + std::experimental::string_view strv{str}; + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + // stress test + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + ofs.close(); + + // sanity check on the written file + std::ifstream ifs(filename); + std::size_t count = 0; + char c; + while (count <= (2 * size) + 4) + { + ifs >> c; + if (ifs.good() && c == fillc) + { + ++count; + c = '0'; + } + else + break; + } + + VERIFY( count == 2 * size ); +} + +int +main() +{ + test05(1); + test05(1000); + test05(10000); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/3.cc new file mode 100644 index 000000000..fc4cd254c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/char/3.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +#include <experimental/string_view> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// libstdc++/2830 +void +test09() +{ + bool test [[gnu::unused]] = true; + + std::experimental::string_view foo{"peace\0\0\0& love"}; + + std::ostringstream oss1; + oss1 << foo; + VERIFY( oss1.str() == foo ); + + std::ostringstream oss2; + oss2.width(20); + oss2 << foo; + VERIFY( oss2.str() != foo ); + VERIFY( oss2.str().size() == 20 ); +} + +int +main() +{ + test09(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/pod/10081-out.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/pod/10081-out.cc new file mode 100644 index 000000000..75c435d80 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/pod/10081-out.cc @@ -0,0 +1,77 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// class basic_istream::sentry + +#include <experimental/string_view> +#include <ostream> +#include <sstream> +#include <locale> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +void +test01() +{ + using namespace std; + + using __gnu_test::pod_ushort; + typedef experimental::basic_string_view<pod_ushort> string_type; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_ostream<pod_ushort> ostream_type; + + bool test [[gnu::unused]] = true; + + string_type str; + stringbuf_type strbuf01; + ostream_type stream(&strbuf01); + + try + { + stream << str; + } + catch (std::bad_cast& obj) + { + // Ok, throws bad_cast because locale has no ctype facet. + } + catch (...) + { + VERIFY( false ); + } + + const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); + stream.imbue(loc); + try + { + stream << str; + } + catch (...) + { + VERIFY( false ); + } +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/1.cc new file mode 100644 index 000000000..e2ed3f2fb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/1.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +#include <experimental/string_view> +#include <stdexcept> +#include <sstream> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + typedef std::experimental::wstring_view::const_reference cref; + typedef std::experimental::wstring_view::reference ref; + + const std::experimental::wstring_view str01(L"sailing grand traverse bay\n" + L"\t\t\t from Elk Rapids to the point reminds me of miles"); + const std::experimental::wstring_view str02(L"sailing"); + const std::experimental::wstring_view str03(L"grand"); + const std::experimental::wstring_view str04(L"traverse"); + const std::experimental::wstring_view str05; + std::experimental::wstring_view str10; + + // ostream& operator<<(ostream&, const basic_string_view&) + std::wostringstream ostrs01; + try + { + ostrs01 << str01; + VERIFY( ostrs01.str() == str01 ); + } + catch(std::exception& fail) + { + VERIFY( false ); + } + + std::experimental::wstring_view hello_world; + std::wcout << hello_world; + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/2.cc new file mode 100644 index 000000000..419ff7455 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/2.cc @@ -0,0 +1,91 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +#include <experimental/string_view> +#include <string> +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +// testing basic_filebuf::xsputn via stress testing with large string_views +// based on a bug report libstdc++ 9 +// mode == out +void +test05(std::size_t size) +{ + bool test [[gnu::unused]] = true; + + const char filename[] = "inserters_extractors-2.txt"; + const wchar_t fillc = L'f'; + std::wofstream ofs(filename); + std::wstring str(size, fillc); + std::experimental::wstring_view strv(str); + + // sanity checks + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + // stress test + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + ofs << str << std::endl; + if (!ofs.good()) + test = false; + + VERIFY( str.size() == size ); + VERIFY( ofs.good() ); + + ofs.close(); + + // sanity check on the written file + std::wifstream ifs(filename); + std::size_t count = 0; + wchar_t c; + while (count <= (2 * size) + 4) + { + ifs >> c; + if (ifs.good() && c == fillc) + { + ++count; + c = '0'; + } + else + break; + } + + VERIFY( count == 2 * size ); +} + +int +main() +{ + test05(1); + test05(1000); + test05(10000); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/3.cc new file mode 100644 index 000000000..4a3de74eb --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/inserters/wchar_t/3.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// inserters + +// NB: This file is predicated on sstreams, istreams, and ostreams +// working, not to mention other major details like char_traits, and +// all of the string_view class. + +#include <experimental/string_view> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void +test09() +{ + bool test [[gnu::unused]] = true; + + std::experimental::wstring_view foo{L"peace\0\0\0& love"}; + + std::wostringstream oss1; + oss1 << foo; + VERIFY( oss1.str() == foo ); + + std::wostringstream oss2; + oss2.width(20); + oss2 << foo; + VERIFY( oss2.str() != foo ); + VERIFY( oss2.str().size() == 20 ); +} + +int +main() +{ + test09(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/types.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/types.cc new file mode 100644 index 000000000..3ab1037c4 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/types.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <type_traits> + +void +test01() +{ + using namespace std::experimental::literals::string_view_literals; + + static_assert(std::is_same<decltype("Hello"sv), std::experimental::string_view>::value, + "\"Hello\"s is std::string_view"); + + static_assert(std::is_same<decltype(u8"Hello"sv), std::experimental::string_view>::value, + "u8\"Hello\"s is std::string_view"); + + static_assert(std::is_same<decltype(L"Hello"sv), std::experimental::wstring_view>::value, + "L\"Hello\"s is std::wstring_view"); + + static_assert(std::is_same<decltype(u"Hello"sv), std::experimental::u16string_view>::value, + "u\"Hello\"s is std::u16string_view"); + + static_assert(std::is_same<decltype(U"Hello"sv), std::experimental::u32string_view>::value, + "U\"Hello\"s is std::u32string_view"); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/values.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/values.cc new file mode 100644 index 000000000..1343eec75 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/literals/values.cc @@ -0,0 +1,46 @@ +// { dg-do run } +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std::experimental::literals::string_view_literals; + + std::experimental::string_view planet = "Mercury"sv; + std::experimental::wstring_view wplanet = L"Venus"sv; + std::experimental::string_view u8planet = u8"Mars"sv; + std::experimental::u16string_view u16planet = u"Juiter"sv; + std::experimental::u32string_view u32planet = U"Saturn"sv; + + VERIFY( planet == std::experimental::string_view("Mercury") ); + VERIFY( wplanet == std::experimental::wstring_view(L"Venus") ); + VERIFY( u8planet == std::experimental::string_view(u8"Mars") ); + VERIFY( u16planet == std::experimental::u16string_view(u"Juiter") ); + VERIFY( u32planet == std::experimental::u32string_view(U"Saturn") ); +} + +int +main() +{ + test01(); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc new file mode 100644 index 000000000..0ce1fbc26 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/char/1.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + using namespace std::experimental; + + string_view str0{"olympus mons"}; + string_view::pointer p = str0.data(); + str0.remove_prefix(4); + VERIFY( str0.data() == p + 4); + VERIFY( str0.length() == 8 ); + VERIFY( str0 == string_view{"pus mons"} ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/1.cc new file mode 100644 index 000000000..fe4f1b7a0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_prefix/wchar_t/1.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + using namespace std::experimental; + + wstring_view str0{L"olympus mons"}; + wstring_view::pointer p = str0.data(); + str0.remove_prefix(4); + VERIFY( str0.data() == p + 4); + VERIFY( str0.length() == 8 ); + VERIFY( str0 == wstring_view{L"pus mons"} ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc new file mode 100644 index 000000000..8ecee8604 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/char/1.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + using namespace std::experimental; + + string_view str0{"olympus mons"}; + string_view::pointer p = str0.data(); + str0.remove_suffix(2); + VERIFY( str0.data() == p); + VERIFY( str0.length() == 10 ); + VERIFY( str0 == string_view{"olympus mo"} ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/1.cc new file mode 100644 index 000000000..bcee5fc76 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/modifiers/remove_suffix/wchar_t/1.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test [[gnu::unused]] = true; + + using namespace std::experimental; + + wstring_view str0{L"olympus mons"}; + wstring_view::pointer p = str0.data(); + str0.remove_suffix(2); + VERIFY( str0.data() == p); + VERIFY( str0.length() == 10 ); + VERIFY( str0 == wstring_view{L"olympus mo"} ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc new file mode 100644 index 000000000..88fd271f6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/1.cc @@ -0,0 +1,134 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::compare +// int compare(const basic_string_view& str) const; +// int compare(size_type pos1, size_type n1, const basic_string_view& str) const; +// int compare(size_type pos1, size_type n1, const basic_string_view& str, +// size_type pos2, size_type n2) const; +// int compare(const charT* s) const; +// int compare(size_type pos1, size_type n1, +// const charT* s, size_type n2 = npos) const; + +// NB compare should be thought of as a lexographical compare, ie how +// things would be sorted in a dictionary. + +#include <experimental/string_view> +#include <cstring> +#include <testsuite_hooks.h> + +enum want_value {lt=0, z=1, gt=2}; + +int +test_value(int result, want_value expected); + +int +test_value(int result, want_value expected) +{ + bool test [[gnu::unused]] = true; + bool pass = false; + + switch (expected) { + case lt: + if (result < 0) + pass = true; + break; + case z: + if (!result) + pass = true; + break; + case gt: + if (result > 0) + pass = true; + break; + default: + pass = false; //should not get here + } + VERIFY(pass); + return 0; +} + + +int +test01() +{ + using namespace std::experimental; + + string_view str_0("costa rica"); + string_view str_1("costa marbella"); + string_view str_2; + + //sanity check + test_value(strcmp("costa marbella", "costa rica"), lt); + test_value(strcmp("costa rica", "costa rica"), z); + test_value(strcmp(str_1.data(), str_0.data()), lt); + test_value(strcmp(str_0.data(), str_1.data()), gt); + test_value(strncmp(str_1.data(), str_0.data(), 6), z); + test_value(strncmp(str_1.data(), str_0.data(), 14), lt); + test_value(memcmp(str_1.data(), str_0.data(), 6), z); + test_value(memcmp(str_1.data(), str_0.data(), 14), lt); + test_value(memcmp("costa marbella", "costa rica", 14), lt); + + // int compare(const basic_string_view& str) const; + test_value(str_0.compare(str_1), gt); //because r>m + test_value(str_1.compare(str_0), lt); //because m<r + str_2 = str_0; + test_value(str_2.compare(str_0), z); + str_2 = "cost"; + test_value(str_2.compare(str_0), lt); + str_2 = "costa ricans"; + test_value(str_2.compare(str_0), gt); + + // int compare(size_type pos1, size_type n1, const basic_string_view& str) const; + test_value(str_1.compare(0, 6, str_0), lt); + str_2 = "cost"; + test_value(str_1.compare(0, 4, str_2), z); + test_value(str_1.compare(0, 5, str_2), gt); + + // int compare(size_type pos1, size_type n1, const basic_string_view& str, + // size_type pos2, size_type n2) const; + test_value(str_1.compare(0, 6, str_0, 0, 6), z); + test_value(str_1.compare(0, 7, str_0, 0, 7), lt); + test_value(str_0.compare(0, 7, str_1, 0, 7), gt); + + // int compare(const charT* s) const; + test_value(str_0.compare("costa marbella"), gt); + test_value(str_1.compare("costa rica"), lt); + str_2 = str_0; + test_value(str_2.compare("costa rica"), z); + test_value(str_2.compare("cost"), gt); + test_value(str_2.compare("costa ricans"), lt); + + // int compare(size_type pos, size_type n1, const charT* str, + // size_type n2 = npos) const; + test_value(str_1.compare(0, 6, "costa rica", 0, 6), z); + test_value(str_1.compare(0, 7, "costa rica", 0, 7), lt); + test_value(str_0.compare(0, 7, "costa marbella", 0, 7), gt); + + return 0; +} + + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc new file mode 100644 index 000000000..5523ea685 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/char/13650.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::compare [lib.string_view::compare] + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// libstdc++/13650 +void +test01() +{ + using namespace std::experimental; + bool test [[gnu::unused]] = true; + + const char lit_01[]{ 'w', 'e', '\0', 'r', 'd' }; + const char lit_02[]{ 'w', 'e', 'i', '\0', 'd' }; + + const char lit_ref_a[]{ 'w', 'e', '\0', 'q', 'd' }; + const string_view str_a(lit_ref_a, 5); + VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 ); + + const char lit_ref_b[]{ 'w', 'e', 'i' }; + const string_view str_b(lit_ref_b, 3); + VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc new file mode 100644 index 000000000..42d06c9e5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/1.cc @@ -0,0 +1,134 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::compare +// int compare(const basic_string_view& str) const; +// int compare(size_type pos1, size_type n1, const basic_string_view& str) const; +// int compare(size_type pos1, size_type n1, const basic_string_view& str, +// size_type pos2, size_type n2) const; +// int compare(const charT* s) const; +// int compare(size_type pos1, size_type n1, +// const charT* s, size_type n2 = npos) const; + +// NB compare should be thought of as a lexographical compare, ie how +// things would be sorted in a dictionary. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +enum want_value {lt=0, z=1, gt=2}; + +int +test_value(int result, want_value expected); + +int +test_value(int result, want_value expected) +{ + bool test [[gnu::unused]] = true; + bool pass = false; + + switch (expected) { + case lt: + if (result < 0) + pass = true; + break; + case z: + if (!result) + pass = true; + break; + case gt: + if (result > 0) + pass = true; + break; + default: + pass = false; //should not get here + } + + VERIFY(pass); + return 0; +} + + +int +test01() +{ + using namespace std::experimental; + + wstring_view str_0(L"costa rica"); + wstring_view str_1(L"costa marbella"); + wstring_view str_2; + + //sanity check + test_value(wcscmp(L"costa marbella", L"costa rica"), lt); + test_value(wcscmp(L"costa rica", L"costa rica"), z); + test_value(wcscmp(str_1.data(), str_0.data()), lt); + test_value(wcscmp(str_0.data(), str_1.data()), gt); + test_value(wcsncmp(str_1.data(), str_0.data(), 6), z); + test_value(wcsncmp(str_1.data(), str_0.data(), 14), lt); + test_value(wmemcmp(str_1.data(), str_0.data(), 6), z); + test_value(wmemcmp(str_1.data(), str_0.data(), 14), lt); + test_value(wmemcmp(L"costa marbella", L"costa rica", 14), lt); + + // int compare(const basic_string_view& str) const; + test_value(str_0.compare(str_1), gt); //because r>m + test_value(str_1.compare(str_0), lt); //because m<r + str_2 = str_0; + test_value(str_2.compare(str_0), z); + str_2 = L"cost"; + test_value(str_2.compare(str_0), lt); + str_2 = L"costa ricans"; + test_value(str_2.compare(str_0), gt); + + // int compare(size_type pos1, size_type n1, const basic_string_view& str) const; + test_value(str_1.compare(0, 6, str_0), lt); + str_2 = L"cost"; + test_value(str_1.compare(0, 4, str_2), z); + test_value(str_1.compare(0, 5, str_2), gt); + + // int compare(size_type pos1, size_type n1, const basic_string_view& str, + // size_type pos2, size_type n2) const; + test_value(str_1.compare(0, 6, str_0, 0, 6), z); + test_value(str_1.compare(0, 7, str_0, 0, 7), lt); + test_value(str_0.compare(0, 7, str_1, 0, 7), gt); + + // int compare(const charT* s) const; + test_value(str_0.compare(L"costa marbella"), gt); + test_value(str_1.compare(L"costa rica"), lt); + str_2 = str_0; + test_value(str_2.compare(L"costa rica"), z); + test_value(str_2.compare(L"cost"), gt); + test_value(str_2.compare(L"costa ricans"), lt); + + // int compare(size_type pos, size_type n1, const charT* str, + // size_type n2 = npos) const; + test_value(str_1.compare(0, 6, L"costa rica", 0, 6), z); + test_value(str_1.compare(0, 7, L"costa rica", 0, 7), lt); + test_value(str_0.compare(0, 7, L"costa marbella", 0, 7), gt); + + return 0; +} + + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc new file mode 100644 index 000000000..f0692743a --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/compare/wchar_t/13650.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::compare [lib.string_view::compare] + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// libstdc++/13650 +void +test01() +{ + using namespace std::experimental; + bool test [[gnu::unused]] = true; + + const wchar_t lit_01[] = { L'w', L'e', L'\0', L'r', L'd' }; + const wchar_t lit_02[] = { L'w', L'e', L'i', L'\0', L'd' }; + + const wchar_t lit_ref_a[] = { L'w', L'e', L'\0', L'q', L'd' }; + const wstring_view str_a(lit_ref_a, 5); + VERIFY( str_a.compare(0, 5, lit_01, 5) < 0 ); + + const wchar_t lit_ref_b[] = { L'w', L'e', L'i' }; + const wstring_view str_b(lit_ref_b, 3); + VERIFY( str_b.compare(0, 3, lit_02, 5) < 0 ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc new file mode 100644 index 000000000..25b2af133 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/char/1.cc @@ -0,0 +1,50 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013 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/>. + +// basic_string_view::copy + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + + const char str_lit01[] = "123456789A"; + const std::experimental::string_view str01(str_lit01); + char buffer[4] = { 0 }; + + csize_type len = str01.copy(buffer, sizeof(buffer), 8); + VERIFY( 2 == len ); + VERIFY( '9' == buffer[0] ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc new file mode 100644 index 000000000..0348e1f98 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/copy/wchar_t/1.cc @@ -0,0 +1,51 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013 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/>. + +// basic_string_view::copy + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + csize_type csz01; + + const wchar_t str_lit01[] = L"123456789A"; + const std::experimental::wstring_view str01(str_lit01); + wchar_t buffer[4] = { 0 }; + + csize_type len = str01.copy(buffer, sizeof(buffer), 8); + VERIFY( 2 == len ); + VERIFY( L'9' == buffer[0] ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc new file mode 100644 index 000000000..be75de917 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/char/1.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013 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/>. + +// string_view operations + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::string_view empty; + + // data() for size == 0 is non-NULL. + VERIFY( empty.size() == 0 ); + const std::experimental::string_view::value_type* p = empty.data(); + VERIFY( p ); + + return 0; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc new file mode 100644 index 000000000..5e00b00b6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/data/wchar_t/1.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013 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/>. + +// string_view operations + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::wstring_view empty; + + // data() for size == 0 is non-NULL. + VERIFY( empty.size() == 0 ); + const std::experimental::wstring_view::value_type* p = empty.data(); + VERIFY( p ); + + return 0; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/1.cc new file mode 100644 index 000000000..d48d058da --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/1.cc @@ -0,0 +1,98 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + typedef std::experimental::string_view::const_reference cref; + typedef std::experimental::string_view::reference ref; + csize_type npos = std::experimental::string_view::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "mave"; + const std::experimental::string_view str01("mavericks, santa cruz"); + std::experimental::string_view str02(str_lit01); + std::experimental::string_view str03("s, s"); + std::experimental::string_view str04; + + // size_type find(const string_view&, size_type pos = 0) const; + csz01 = str01.find(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str01, 4); + VERIFY( csz01 == npos ); + csz01 = str01.find(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str02, 3); + VERIFY( csz01 == npos ); + csz01 = str01.find(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 12); + VERIFY( csz01 == npos ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + csz01 = str01.find(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.find(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.find(str04, str01.size()+1); + VERIFY( csz01 == npos ); + + // size_type find(const char* s, size_type pos, size_type n) const; + csz01 = str01.find(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type find(const char* s, size_type pos = 0) const; + csz01 = str01.find(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3); + VERIFY( csz01 == npos ); + + // size_type find(char c, size_type pos = 0) const; + csz01 = str01.find('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.find('/'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/2.cc new file mode 100644 index 000000000..404c039dc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/2.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find_first_of + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test02() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + csize_type npos = std::experimental::string_view::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "mave"; + const std::experimental::string_view str01("mavericks, santa cruz"); + std::experimental::string_view str02(str_lit01); + std::experimental::string_view str03("s, s"); + std::experimental::string_view str04; + + // size_type find_first_of(const string_view&, size_type pos = 0) const; + std::experimental::string_view str05("xena rulez"); + csz01 = str01.find_first_of(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str01, 4); + VERIFY( csz01 == 4 ); + csz01 = str01.find_first_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str02, 3); + VERIFY( csz01 == 3 ); + csz01 = str01.find_first_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 12); + VERIFY( csz01 == 16 ); + csz01 = str01.find_first_of(str05, 0); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_of(str05, 4); + VERIFY( csz01 == 4 ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + // However, str1.find_first_of(str2,pos) finds the first character in + // str1 (starting at pos) that exists in str2, which is none for empty str2 + csz01 = str01.find_first_of(str04, 0); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_of(str04, 5); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const char* s, size_type pos, size_type n) const; + csz01 = str01.find_first_of(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const char* s, size_type pos = 0) const; + csz01 = str01.find_first_of(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3); + VERIFY( csz01 == 3 ); + + // size_type find_first_of(char c, size_type pos = 0) const; + csz01 = str01.find_first_of('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + + return test; +} + +int +main() +{ + test02(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/3.cc new file mode 100644 index 000000000..9c84e4db0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/3.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find_first_not_of + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test03() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + csize_type npos = std::experimental::string_view::npos; + csize_type csz01; + + const std::experimental::string_view str01("Bob Rock, per me"); + const char str_lit01[] = "Bob Rock"; + std::experimental::string_view str02("ovvero Trivi"); + std::experimental::string_view str03(str_lit01); + std::experimental::string_view str04; + + // size_type find_first_not_of(const string_view&, size_type pos = 0) const; + csz01 = str01.find_first_not_of(str01); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_not_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str02, 10); + VERIFY( csz01 == 10 ); + csz01 = str01.find_first_not_of(str02, 12); + VERIFY( csz01 == 14 ); + csz01 = str01.find_first_not_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_not_of(str03, 15); + VERIFY( csz01 == 15 ); + csz01 = str01.find_first_not_of(str03, 16); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_not_of(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str04, 12); + VERIFY( csz01 == 12 ); + csz01 = str03.find_first_not_of(str01, 0); + VERIFY( csz01 == npos ); + csz01 = str04.find_first_not_of(str02, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_not_of(const char* s, size_type pos, size_type n) const; + csz01 = str01.find_first_not_of(str_lit01, 0, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str_lit01, 0, 8); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_not_of(str_lit01, 10, 0); + VERIFY( csz01 == 10 ); + + // size_type find_first_not_of(const char* s, size_type pos = 0) const; + csz01 = str01.find_first_not_of(str_lit01); + VERIFY( csz01 == 8 ); + csz01 = str02.find_first_not_of(str_lit01, 2); + VERIFY( csz01 == 2 ); + + // size_type find_first_not_of(char c, size_type pos = 0) const; + csz01 = str01.find_first_not_of('B'); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_not_of('o', 1); + VERIFY( csz01 == 2 ); + csz01 = str02.find_first_not_of('z'); + VERIFY( csz01 == 0 ); + csz01 = str04.find_first_not_of('S'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/4.cc new file mode 100644 index 000000000..4be57172c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/char/4.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// libstdc++/31401 +void +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + csize_type npos = std::experimental::string_view::npos; + + std::experimental::string_view use = "anu"; + csize_type pos1 = use.find("a", npos); + + VERIFY( pos1 == npos ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/1.cc new file mode 100644 index 000000000..57bcdf03d --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/1.cc @@ -0,0 +1,98 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + typedef std::experimental::wstring_view::const_reference cref; + typedef std::experimental::wstring_view::reference ref; + csize_type npos = std::experimental::wstring_view::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"mave"; + const std::experimental::wstring_view str01(L"mavericks, santa cruz"); + std::experimental::wstring_view str02(str_lit01); + std::experimental::wstring_view str03(L"s, s"); + std::experimental::wstring_view str04; + + // size_type find(const wstring_view&, size_type pos = 0) const; + csz01 = str01.find(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str01, 4); + VERIFY( csz01 == npos ); + csz01 = str01.find(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str02, 3); + VERIFY( csz01 == npos ); + csz01 = str01.find(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find(str03, 12); + VERIFY( csz01 == npos ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + csz01 = str01.find(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.find(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.find(str04, str01.size()+1); + VERIFY( csz01 == npos ); + + // size_type find(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.find(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type find(const wchar_t* s, size_type pos = 0) const; + csz01 = str01.find(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find(str_lit01, 3); + VERIFY( csz01 == npos ); + + // size_type find(wchar_t c, size_type pos = 0) const; + csz01 = str01.find(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.find(L'/'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/2.cc new file mode 100644 index 000000000..0ba97b796 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/2.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find_first_of + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test02() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + csize_type npos = std::experimental::wstring_view::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"mave"; + const std::experimental::wstring_view str01(L"mavericks, santa cruz"); + std::experimental::wstring_view str02(str_lit01); + std::experimental::wstring_view str03(L"s, s"); + std::experimental::wstring_view str04; + + // size_type find_first_of(const wstring_view&, size_type pos = 0) const; + std::experimental::wstring_view str05(L"xena rulez"); + csz01 = str01.find_first_of(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str01, 4); + VERIFY( csz01 == 4 ); + csz01 = str01.find_first_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str02, 3); + VERIFY( csz01 == 3 ); + csz01 = str01.find_first_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 3); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_of(str03, 12); + VERIFY( csz01 == 16 ); + csz01 = str01.find_first_of(str05, 0); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_of(str05, 4); + VERIFY( csz01 == 4 ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + // However, str1.find_first_of(str2,pos) finds the first character in + // str1 (starting at pos) that exists in str2, which is none for empty str2 + csz01 = str01.find_first_of(str04, 0); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_of(str04, 5); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.find_first_of(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_of(const wchar_t* s, size_type pos = 0) const; + csz01 = str01.find_first_of(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_of(str_lit01, 3); + VERIFY( csz01 == 3 ); + + // size_type find_first_of(wchar_t c, size_type pos = 0) const; + csz01 = str01.find_first_of(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + + return test; +} + +int +main() +{ + test02(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/3.cc new file mode 100644 index 000000000..89b88edb5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/3.cc @@ -0,0 +1,97 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find_first_not_of + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +bool +test03() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + csize_type npos = std::experimental::wstring_view::npos; + csize_type csz01; + + const std::experimental::wstring_view str01(L"Bob Rock, per me"); + const wchar_t str_lit01[] = L"Bob Rock"; + std::experimental::wstring_view str02(L"ovvero Trivi"); + std::experimental::wstring_view str03(str_lit01); + std::experimental::wstring_view str04; + + // size_type find_first_not_of(const string_view&, size_type pos = 0) const; + csz01 = str01.find_first_not_of(str01); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_not_of(str02, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str02, 10); + VERIFY( csz01 == 10 ); + csz01 = str01.find_first_not_of(str02, 12); + VERIFY( csz01 == 14 ); + csz01 = str01.find_first_not_of(str03, 0); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_not_of(str03, 15); + VERIFY( csz01 == 15 ); + csz01 = str01.find_first_not_of(str03, 16); + VERIFY( csz01 == npos ); + csz01 = str01.find_first_not_of(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str04, 12); + VERIFY( csz01 == 12 ); + csz01 = str03.find_first_not_of(str01, 0); + VERIFY( csz01 == npos ); + csz01 = str04.find_first_not_of(str02, 0); + VERIFY( csz01 == npos ); + + // size_type find_first_not_of(const char* s, size_type pos, size_type n) const; + csz01 = str01.find_first_not_of(str_lit01, 0, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.find_first_not_of(str_lit01, 0, 8); + VERIFY( csz01 == 8 ); + csz01 = str01.find_first_not_of(str_lit01, 10, 0); + VERIFY( csz01 == 10 ); + + // size_type find_first_not_of(const char* s, size_type pos = 0) const; + csz01 = str01.find_first_not_of(str_lit01); + VERIFY( csz01 == 8 ); + csz01 = str02.find_first_not_of(str_lit01, 2); + VERIFY( csz01 == 2 ); + + // size_type find_first_not_of(char c, size_type pos = 0) const; + csz01 = str01.find_first_not_of(L'B'); + VERIFY( csz01 == 1 ); + csz01 = str01.find_first_not_of(L'o', 1); + VERIFY( csz01 == 2 ); + csz01 = str02.find_first_not_of(L'z'); + VERIFY( csz01 == 0 ); + csz01 = str04.find_first_not_of(L'S'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/4.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/4.cc new file mode 100644 index 000000000..b60ce0be7 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/find/wchar_t/4.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view find + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// libstdc++/31401 +void +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + csize_type npos = std::experimental::wstring_view::npos; + + std::experimental::wstring_view use = L"anu"; + csize_type pos1 = use.find(L"a", npos); + + VERIFY( pos1 == npos ); +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/1.cc new file mode 100644 index 000000000..7a36677e9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/1.cc @@ -0,0 +1,98 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view rfind + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + typedef std::experimental::string_view::const_reference cref; + typedef std::experimental::string_view::reference ref; + csize_type npos = std::experimental::string_view::npos; + csize_type csz01, csz02; + + const char str_lit01[] = "mave"; + const std::experimental::string_view str01("mavericks, santa cruz"); + std::experimental::string_view str02(str_lit01); + std::experimental::string_view str03("s, s"); + std::experimental::string_view str04; + + // size_type rfind(const string_view&, size_type pos = 0) const; + csz01 = str01.rfind(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str01, 4); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02,3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str03); + VERIFY( csz01 == 8 ); + csz01 = str01.rfind(str03, 3); + VERIFY( csz01 == npos ); + csz01 = str01.rfind(str03, 12); + VERIFY( csz01 == 8 ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + csz01 = str01.rfind(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.rfind(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.rfind(str04, str01.size()+1); + VERIFY( csz01 == str01.size() ); + + // size_type rfind(const char* s, size_type pos, size_type n) const; + csz01 = str01.rfind(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type rfind(const char* s, size_type pos = 0) const; + csz01 = str01.rfind(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3); + VERIFY( csz01 == 0 ); + + // size_type rfind(char c, size_type pos = 0) const; + csz01 = str01.rfind('z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.rfind('/'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/2.cc new file mode 100644 index 000000000..daf6e7d12 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/2.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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. +// { dg-options "-std=gnu++1y" } + +// 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view::find_last_of + +bool +test02() +{ + bool test [[gnu::unused]] = true; + + std::experimental::string_view z("ab"); + std::experimental::string_view::size_type pos; + pos = z.find_last_of("ab"); + VERIFY( pos == 1 ); + pos = z.find_last_of("Xa"); + VERIFY( pos == 0 ); + pos = z.find_last_of("Xb"); + VERIFY( pos == 1 ); + pos = z.find_last_of("XYZ"); + VERIFY( pos == std::experimental::string_view::npos ); + pos = z.find_last_of('a'); + VERIFY( pos == 0 ); + pos = z.find_last_of('b'); + VERIFY( pos == 1 ); + pos = z.find_last_of('X'); + VERIFY( pos == std::experimental::string_view::npos ); + + return test; +} + +int +main() +{ + test02(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/3.cc new file mode 100644 index 000000000..48de81d7b --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/char/3.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view::find_last_not_of + +bool +test03() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + std::experimental::string_view::size_type pos; + csize_type npos = std::experimental::string_view::npos; + + std::experimental::string_view x; + pos = x.find_last_not_of('X'); + VERIFY( pos == npos ); + pos = x.find_last_not_of("XYZ"); + VERIFY( pos == npos ); + + std::experimental::string_view y("a"); + pos = y.find_last_not_of('X'); + VERIFY( pos == 0 ); + pos = y.find_last_not_of('a'); + VERIFY( pos == npos ); + pos = y.find_last_not_of("XYZ"); + VERIFY( pos == 0 ); + pos = y.find_last_not_of("a"); + VERIFY( pos == npos ); + + std::experimental::string_view z("ab"); + pos = z.find_last_not_of('X'); + VERIFY( pos == 1 ); + pos = z.find_last_not_of("XYZ"); + VERIFY( pos == 1 ); + pos = z.find_last_not_of('b'); + VERIFY( pos == 0 ); + pos = z.find_last_not_of("Xb"); + VERIFY( pos == 0 ); + pos = z.find_last_not_of("Xa"); + VERIFY( pos == 1 ); + + return test; +} +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/1.cc new file mode 100644 index 000000000..1074f94b6 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/1.cc @@ -0,0 +1,98 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view rfind + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + typedef std::experimental::wstring_view::const_reference cref; + typedef std::experimental::wstring_view::reference ref; + csize_type npos = std::experimental::wstring_view::npos; + csize_type csz01, csz02; + + const wchar_t str_lit01[] = L"mave"; + const std::experimental::wstring_view str01(L"mavericks, santa cruz"); + std::experimental::wstring_view str02(str_lit01); + std::experimental::wstring_view str03(L"s, s"); + std::experimental::wstring_view str04; + + // size_type rfind(const wstring_view&, size_type pos = 0) const; + csz01 = str01.rfind(str01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str01, 4); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02,3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str02); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str03); + VERIFY( csz01 == 8 ); + csz01 = str01.rfind(str03, 3); + VERIFY( csz01 == npos ); + csz01 = str01.rfind(str03, 12); + VERIFY( csz01 == 8 ); + + // An empty string_view consists of no characters + // therefore it should be found at every point in a string_view, + // except beyond the end + csz01 = str01.rfind(str04, 0); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str04, 5); + VERIFY( csz01 == 5 ); + csz01 = str01.rfind(str04, str01.size()); + VERIFY( csz01 == str01.size() ); + csz01 = str01.rfind(str04, str01.size()+1); + VERIFY( csz01 == str01.size() ); + + // size_type rfind(const wchar_t* s, size_type pos, size_type n) const; + csz01 = str01.rfind(str_lit01, 0, 3); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3, 0); + VERIFY( csz01 == 3 ); + + // size_type rfind(const wchar_t* s, size_type pos = 0) const; + csz01 = str01.rfind(str_lit01); + VERIFY( csz01 == 0 ); + csz01 = str01.rfind(str_lit01, 3); + VERIFY( csz01 == 0 ); + + // size_type rfind(wchar_t c, size_type pos = 0) const; + csz01 = str01.rfind(L'z'); + csz02 = str01.size() - 1; + VERIFY( csz01 == csz02 ); + csz01 = str01.rfind(L'/'); + VERIFY( csz01 == npos ); + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/2.cc new file mode 100644 index 000000000..772496b7c --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/2.cc @@ -0,0 +1,56 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view::find_last_of + +bool +test02() +{ + bool test [[gnu::unused]] = true; + + std::experimental::wstring_view::size_type pos; + std::experimental::wstring_view z(L"ab"); + pos = z.find_last_of(L"ab"); + VERIFY( pos == 1 ); + pos = z.find_last_of(L"Xa"); + VERIFY( pos == 0 ); + pos = z.find_last_of(L"Xb"); + VERIFY( pos == 1 ); + pos = z.find_last_of(L"XYZ"); + VERIFY( pos == std::experimental::wstring_view::npos ); + pos = z.find_last_of(L'a'); + VERIFY( pos == 0 ); + pos = z.find_last_of(L'b'); + VERIFY( pos == 1 ); + pos = z.find_last_of(L'X'); + VERIFY( pos == std::experimental::wstring_view::npos ); + + return test; +} + +int +main() +{ + test02(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/3.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/3.cc new file mode 100644 index 000000000..5313bdc51 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/rfind/wchar_t/3.cc @@ -0,0 +1,70 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +// basic_string_view::find_last_not_of + +bool +test03() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + std::experimental::wstring_view::size_type pos; + csize_type npos = std::experimental::wstring_view::npos; + + std::experimental::wstring_view x; + pos = x.find_last_not_of(L'X'); + VERIFY( pos == npos ); + pos = x.find_last_not_of(L"XYZ"); + VERIFY( pos == npos ); + + std::experimental::wstring_view y(L"a"); + pos = y.find_last_not_of(L'X'); + VERIFY( pos == 0 ); + pos = y.find_last_not_of(L'a'); + VERIFY( pos == npos ); + pos = y.find_last_not_of(L"XYZ"); + VERIFY( pos == 0 ); + pos = y.find_last_not_of(L"a"); + VERIFY( pos == npos ); + + std::experimental::wstring_view z(L"ab"); + pos = z.find_last_not_of(L'X'); + VERIFY( pos == 1 ); + pos = z.find_last_not_of(L"XYZ"); + VERIFY( pos == 1 ); + pos = z.find_last_not_of(L'b'); + VERIFY( pos == 0 ); + pos = z.find_last_not_of(L"Xb"); + VERIFY( pos == 0 ); + pos = z.find_last_not_of(L"Xa"); + VERIFY( pos == 1 ); + + return test; +} +int +main() +{ + test03(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/char/1.cc new file mode 100644 index 000000000..2f430ba16 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/char/1.cc @@ -0,0 +1,83 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::substr + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::string_view::size_type csize_type; + typedef std::experimental::string_view::const_reference cref; + typedef std::experimental::string_view::reference ref; + csize_type csz01; + + const char str_lit01[] = "rockaway, pacifica"; + const std::experimental::string_view str01(str_lit01); + std::experimental::string_view str02; + + // basic_string_view<charT, _Traits, _Alloc> + // substr(size_type pos = 0, size_type n = npos) const; + csz01 = str01.size(); + str02 = str01.substr(0, 1); + VERIFY( str02 == "r" ); + str02 = str01.substr(10); + VERIFY( str02 == "pacifica" ); + + try + { + str02 = str01.substr(csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + + try + { + str02 = str01.substr(csz01); + VERIFY( str02.size() == 0 ); + VERIFY( str02.begin() == str01.end() ); + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/wchar_t/1.cc new file mode 100644 index 000000000..6be8838e0 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operations/substr/wchar_t/1.cc @@ -0,0 +1,83 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view::substr + +#include <experimental/string_view> +#include <stdexcept> +#include <testsuite_hooks.h> + +bool +test01() +{ + bool test [[gnu::unused]] = true; + + typedef std::experimental::wstring_view::size_type csize_type; + typedef std::experimental::wstring_view::const_reference cref; + typedef std::experimental::wstring_view::reference ref; + csize_type csz01; + + const wchar_t str_lit01[] = L"rockaway, pacifica"; + const std::experimental::wstring_view str01(str_lit01); + std::experimental::wstring_view str02; + + // basic_string_view<charT, _Traits, _Alloc> + // substr(size_type pos = 0, size_type n = npos) const; + csz01 = str01.size(); + str02 = str01.substr(0, 1); + VERIFY( str02 == L"r" ); + str02 = str01.substr(10); + VERIFY( str02 == L"pacifica" ); + + try + { + str02 = str01.substr(csz01 + 1); + VERIFY( false ); + } + catch(std::out_of_range& fail) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + + try + { + str02 = str01.substr(csz01); + VERIFY( str02.size() == 0 ); + VERIFY( str02.begin() == str01.end() ); + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } + + return test; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/char/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/char/2.cc new file mode 100644 index 000000000..6368c1c90 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/char/2.cc @@ -0,0 +1,246 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string non-member functions + +// operator== +/* +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// operator!= +/* +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// operator< +/* +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// operator> +/* +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// operator<= +/* +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +// operator>= +/* +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const basic_string<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const charT* lhs, + const basic_string<charT,traits,Allocator>& rhs); +*/ + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::string_view str_0("costa rica"); + std::experimental::string_view str_1("costa marbella"); + std::experimental::string_view str_2("cost"); + std::experimental::string_view str_3("costa ricans"); + std::experimental::string_view str_4; + + str_4 = str_0; + //comparisons between string objects + VERIFY( !(str_0 == str_1) ); + VERIFY( !(str_0 == str_2) ); + VERIFY( !(str_0 == str_3) ); + VERIFY( !(str_1 == str_0) ); + VERIFY( !(str_2 == str_0) ); + VERIFY( !(str_3 == str_0) ); + VERIFY( str_4 == str_0 ); + VERIFY( str_0 == str_4 ); + + VERIFY( str_0 != str_1 ); + VERIFY( str_0 != str_2 ); + VERIFY( str_0 != str_3 ); + VERIFY( str_1 != str_0 ); + VERIFY( str_2 != str_0 ); + VERIFY( str_3 != str_0 ); + VERIFY( !(str_0 != str_4) ); + VERIFY( !(str_4 != str_0) ); + + VERIFY( str_0 > str_1 ); //true cuz r>m + VERIFY( str_0 > str_2 ); + VERIFY( !(str_0 > str_3) ); + VERIFY( !(str_1 > str_0) ); //false cuz m<r + VERIFY( !(str_2 > str_0) ); + VERIFY( str_3 > str_0 ); + VERIFY( !(str_0 > str_4) ); + VERIFY( !(str_4 > str_0) ); + + VERIFY( !(str_0 < str_1) ); //false cuz r>m + VERIFY( !(str_0 < str_2) ); + VERIFY( str_0 < str_3 ); + VERIFY( str_1 < str_0 ); //true cuz m<r + VERIFY( str_2 < str_0 ); + VERIFY( !(str_3 < str_0) ); + VERIFY( !(str_0 < str_4) ); + VERIFY( !(str_4 < str_0) ); + + VERIFY( str_0 >= str_1 ); //true cuz r>m + VERIFY( str_0 >= str_2 ); + VERIFY( !(str_0 >= str_3) ); + VERIFY( !(str_1 >= str_0) );//false cuz m<r + VERIFY( !(str_2 >= str_0) ); + VERIFY( str_3 >= str_0 ); + VERIFY( str_0 >= str_4 ); + VERIFY( str_4 >= str_0 ); + + VERIFY( !(str_0 <= str_1) );//false cuz r>m + VERIFY( !(str_0 <= str_2) ); + VERIFY( str_0 <= str_3 ); + VERIFY( str_1 <= str_0 );//true cuz m<r + VERIFY( str_2 <= str_0 ); + VERIFY( !(str_3 <= str_0) ); + VERIFY( str_0 <= str_4 ); + VERIFY( str_4 <= str_0 ); + + //comparisons between string object and string literal + VERIFY( !(str_0 == "costa marbella") ); + VERIFY( !(str_0 == "cost") ); + VERIFY( !(str_0 == "costa ricans") ); + VERIFY( !("costa marbella" == str_0) ); + VERIFY( !("cost" == str_0) ); + VERIFY( !("costa ricans" == str_0) ); + VERIFY( "costa rica" == str_0 ); + VERIFY( str_0 == "costa rica" ); + + VERIFY( str_0 != "costa marbella" ); + VERIFY( str_0 != "cost" ); + VERIFY( str_0 != "costa ricans" ); + VERIFY( "costa marbella" != str_0 ); + VERIFY( "cost" != str_0 ); + VERIFY( "costa ricans" != str_0 ); + VERIFY( !("costa rica" != str_0) ); + VERIFY( !(str_0 != "costa rica") ); + + VERIFY( str_0 > "costa marbella" ); //true cuz r>m + VERIFY( str_0 > "cost" ); + VERIFY( !(str_0 > "costa ricans") ); + VERIFY( !("costa marbella" > str_0) );//false cuz m<r + VERIFY( !("cost" > str_0) ); + VERIFY( "costa ricans" > str_0 ); + VERIFY( !("costa rica" > str_0) ); + VERIFY( !(str_0 > "costa rica") ); + + VERIFY( !(str_0 < "costa marbella") );//false cuz r>m + VERIFY( !(str_0 < "cost") ); + VERIFY( str_0 < "costa ricans" ); + VERIFY( "costa marbella" < str_0 );//true cuz m<r + VERIFY( "cost" < str_0 ); + VERIFY( !("costa ricans" < str_0) ); + VERIFY( !("costa rica" < str_0) ); + VERIFY( !(str_0 < "costa rica") ); + + VERIFY( str_0 >= "costa marbella" );//true cuz r>m + VERIFY( str_0 >= "cost" ); + VERIFY( !(str_0 >= "costa ricans") ); + VERIFY( !("costa marbella" >= str_0) );//false cuz m<r + VERIFY( !("cost" >= str_0) ); + VERIFY( "costa ricans" >= str_0 ); + VERIFY( "costa rica" >= str_0 ); + VERIFY( str_0 >= "costa rica" ); + + VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m + VERIFY( !(str_0 <= "cost") ); + VERIFY( str_0 <= "costa ricans" ); + VERIFY( "costa marbella" <= str_0 );//true cuz m<r + VERIFY( "cost" <= str_0 ); + VERIFY( !("costa ricans" <= str_0) ); + VERIFY( "costa rica" <= str_0 ); + VERIFY( str_0 <= "costa rica" ); + + return 0; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/wchar_t/2.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/wchar_t/2.cc new file mode 100644 index 000000000..b83eaee08 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/operators/wchar_t/2.cc @@ -0,0 +1,246 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// basic_string_view non-member functions + +// operator== +/* +template<class charT, class traits, class Allocator> + bool operator==(const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator==(const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// operator!= +/* +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator!=(const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); +*/ + +// operator< +/* +template<class charT, class traits, class Allocator> + bool operator< (const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator< (const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); +*/ + +// operator> +/* +template<class charT, class traits, class Allocator> + bool operator> (const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator> (const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); +*/ + +// operator<= +/* +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator<=(const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); +*/ + +// operator>= +/* +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string_view<charT,traits,Allocator>& lhs, + const basic_string_view<charT,traits,Allocator>& rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const basic_string_view<charT,traits,Allocator>& lhs, + const charT* rhs); + +template<class charT, class traits, class Allocator> + bool operator>=(const charT* lhs, + const basic_string_view<charT,traits,Allocator>& rhs); +*/ + +#include <experimental/string_view> +#include <testsuite_hooks.h> + +int +test01() +{ + bool test [[gnu::unused]] = true; + + std::experimental::wstring_view str_0(L"costa rica"); + std::experimental::wstring_view str_1(L"costa marbella"); + std::experimental::wstring_view str_2(L"cost"); + std::experimental::wstring_view str_3(L"costa ricans"); + std::experimental::wstring_view str_4; + + str_4 = str_0; + //comparisons between string_view objects + VERIFY( !(str_0 == str_1) ); + VERIFY( !(str_0 == str_2) ); + VERIFY( !(str_0 == str_3) ); + VERIFY( !(str_1 == str_0) ); + VERIFY( !(str_2 == str_0) ); + VERIFY( !(str_3 == str_0) ); + VERIFY( str_4 == str_0 ); + VERIFY( str_0 == str_4 ); + + VERIFY( str_0 != str_1 ); + VERIFY( str_0 != str_2 ); + VERIFY( str_0 != str_3 ); + VERIFY( str_1 != str_0 ); + VERIFY( str_2 != str_0 ); + VERIFY( str_3 != str_0 ); + VERIFY( !(str_0 != str_4) ); + VERIFY( !(str_4 != str_0) ); + + VERIFY( str_0 > str_1 ); //true cuz r>m + VERIFY( str_0 > str_2 ); + VERIFY( !(str_0 > str_3) ); + VERIFY( !(str_1 > str_0) ); //false cuz m<r + VERIFY( !(str_2 > str_0) ); + VERIFY( str_3 > str_0 ); + VERIFY( !(str_0 > str_4) ); + VERIFY( !(str_4 > str_0) ); + + VERIFY( !(str_0 < str_1) ); //false cuz r>m + VERIFY( !(str_0 < str_2) ); + VERIFY( str_0 < str_3 ); + VERIFY( str_1 < str_0 ); //true cuz m<r + VERIFY( str_2 < str_0 ); + VERIFY( !(str_3 < str_0) ); + VERIFY( !(str_0 < str_4) ); + VERIFY( !(str_4 < str_0) ); + + VERIFY( str_0 >= str_1 ); //true cuz r>m + VERIFY( str_0 >= str_2 ); + VERIFY( !(str_0 >= str_3) ); + VERIFY( !(str_1 >= str_0) );//false cuz m<r + VERIFY( !(str_2 >= str_0) ); + VERIFY( str_3 >= str_0 ); + VERIFY( str_0 >= str_4 ); + VERIFY( str_4 >= str_0 ); + + VERIFY( !(str_0 <= str_1) );//false cuz r>m + VERIFY( !(str_0 <= str_2) ); + VERIFY( str_0 <= str_3 ); + VERIFY( str_1 <= str_0 );//true cuz m<r + VERIFY( str_2 <= str_0 ); + VERIFY( !(str_3 <= str_0) ); + VERIFY( str_0 <= str_4 ); + VERIFY( str_4 <= str_0 ); + + //comparisons between string_view object and string_view literal + VERIFY( !(str_0 == L"costa marbella") ); + VERIFY( !(str_0 == L"cost") ); + VERIFY( !(str_0 == L"costa ricans") ); + VERIFY( !(L"costa marbella" == str_0) ); + VERIFY( !(L"cost" == str_0) ); + VERIFY( !(L"costa ricans" == str_0) ); + VERIFY( L"costa rica" == str_0 ); + VERIFY( str_0 == L"costa rica" ); + + VERIFY( str_0 != L"costa marbella" ); + VERIFY( str_0 != L"cost" ); + VERIFY( str_0 != L"costa ricans" ); + VERIFY( L"costa marbella" != str_0 ); + VERIFY( L"cost" != str_0 ); + VERIFY( L"costa ricans" != str_0 ); + VERIFY( !(L"costa rica" != str_0) ); + VERIFY( !(str_0 != L"costa rica") ); + + VERIFY( str_0 > L"costa marbella" ); //true cuz r>m + VERIFY( str_0 > L"cost" ); + VERIFY( !(str_0 > L"costa ricans") ); + VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r + VERIFY( !(L"cost" > str_0) ); + VERIFY( L"costa ricans" > str_0 ); + VERIFY( !(L"costa rica" > str_0) ); + VERIFY( !(str_0 > L"costa rica") ); + + VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m + VERIFY( !(str_0 < L"cost") ); + VERIFY( str_0 < L"costa ricans" ); + VERIFY( L"costa marbella" < str_0 );//true cuz m<r + VERIFY( L"cost" < str_0 ); + VERIFY( !(L"costa ricans" < str_0) ); + VERIFY( !(L"costa rica" < str_0) ); + VERIFY( !(str_0 < L"costa rica") ); + + VERIFY( str_0 >= L"costa marbella" );//true cuz r>m + VERIFY( str_0 >= L"cost" ); + VERIFY( !(str_0 >= L"costa ricans") ); + VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r + VERIFY( !(L"cost" >= str_0) ); + VERIFY( L"costa ricans" >= str_0 ); + VERIFY( L"costa rica" >= str_0 ); + VERIFY( str_0 >= L"costa rica" ); + + VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m + VERIFY( !(str_0 <= L"cost") ); + VERIFY( str_0 <= L"costa ricans" ); + VERIFY( L"costa marbella" <= str_0 );//true cuz m<r + VERIFY( L"cost" <= str_0 ); + VERIFY( !(L"costa ricans" <= str_0) ); + VERIFY( L"costa rica" <= str_0 ); + VERIFY( str_0 <= L"costa rica" ); + + return 0; +} + +int +main() +{ + test01(); + + return 0; +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc new file mode 100644 index 000000000..db462bcdf --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/char/1.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// 24.6.5, range access [iterator.range] + +#include <experimental/string_view> + +void +test01() +{ + std::experimental::string_view s("Hello, World!"); + std::begin(s); + std::end(s); +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc new file mode 100644 index 000000000..e09046914 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/range_access/wchar_t/1.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +// 24.6.5, range access [iterator.range] + +#include <experimental/string_view> + +void +test01() +{ +#ifdef _GLIBCXX_USE_WCHAR_T + std::experimental::wstring_view ws(L"Hello, World!"); + std::begin(ws); + std::end(ws); +#endif +} diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/1.cc new file mode 100644 index 000000000..83f9d95dc --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/1.cc @@ -0,0 +1,26 @@ +// Copyright (C) 2013-2014 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/>. + + +// This file tests explicit instantiation of basic_string + +#include <experimental/string_view> + +// { dg-do compile } +// { dg-options "-std=gnu++1y" } + +template class std::experimental::basic_string_view<int, std::char_traits<int>>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char/1.cc new file mode 100644 index 000000000..85db99c34 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char/1.cc @@ -0,0 +1,23 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +template class std::experimental::basic_string_view<char>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char16_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char16_t/1.cc new file mode 100644 index 000000000..7b81bcb78 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char16_t/1.cc @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } +// { dg-require-cstdint "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +template class std::experimental::basic_string_view<char16_t>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char32_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char32_t/1.cc new file mode 100644 index 000000000..64f89eb07 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/char32_t/1.cc @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } +// { dg-require-cstdint "" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +template class std::experimental::basic_string_view<char32_t>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/wchar_t/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/wchar_t/1.cc new file mode 100644 index 000000000..749d4ecd5 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/explicit_instantiation/wchar_t/1.cc @@ -0,0 +1,23 @@ +// { dg-do compile } +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> + +template class std::experimental::basic_string_view<wchar_t>; diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/typedefs.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/typedefs.cc new file mode 100644 index 000000000..e04dd4ab9 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/requirements/typedefs.cc @@ -0,0 +1,47 @@ + +// { dg-options "-std=gnu++1y" } +// { dg-do compile } + +// Copyright (C) 2013-2014 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/>. + +#include <experimental/string_view> +#include <testsuite_containers.h> + +namespace __gnu_test +{ + template<typename _Tp1, typename _Tp2> + struct traits<std::experimental::basic_string_view<_Tp1, _Tp2>> : public traits_base + { + typedef std::true_type is_container; + typedef std::true_type is_reversible; + }; +} + +#include <testsuite_containers.h> + +// Check container for required typedefs. + +__gnu_test::basic_types<std::experimental::string_view> t1b; +__gnu_test::reversible_types<std::experimental::string_view> t1r; +typedef typename std::experimental::string_view::traits_type traits_type1; + +#ifdef _GLIBCXX_USE_WCHAR_T +__gnu_test::basic_types<std::experimental::wstring_view> t2b; +__gnu_test::reversible_types<std::experimental::wstring_view> t2r; +typedef typename std::experimental::wstring_view::traits_type traits_type2; +#endif diff --git a/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/types/1.cc b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/types/1.cc new file mode 100644 index 000000000..46ce32103 --- /dev/null +++ b/gcc-4.9/libstdc++-v3/testsuite/experimental/string_view/types/1.cc @@ -0,0 +1,43 @@ +// +// Copyright (C) 2013-2014 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++1y" } +// { dg-do compile } + +#include <experimental/string_view> + +struct T +{ + typedef std::experimental::string_view String_view; + typedef String_view::iterator iterator; + typedef String_view::const_iterator const_iterator; + + char t(iterator f) { return *f; } + char t(const_iterator f) const { return *f; } +}; + +void +f() +{ + std::experimental::string_view s; + T t; + T::const_iterator i = s.begin(); + + t.t(i); +} |