diff options
Diffstat (limited to 'libstdc++-v3/testsuite/18_support/exception_ptr')
8 files changed, 600 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc new file mode 100644 index 000000000..933f41369 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/40296.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 <exception> + +// libstdc++/40296 +bool test01() +{ + std::exception_ptr p; + + return (p == 0); +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc new file mode 100644 index 000000000..4029eaf69 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/current_exception.cc @@ -0,0 +1,91 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at> + +// Copyright (C) 2008, 2009 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/>. + +// current_exception() under various conditions. + +#include <exception> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + exception_ptr ep = current_exception(); + VERIFY( ep == 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + try { + throw 0; + } catch(...) { + exception_ptr ep = current_exception(); + VERIFY( ep != 0 ); + } +} + +void test03() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + try { + throw exception(); + } catch(std::exception&) { + exception_ptr ep = current_exception(); + VERIFY( ep != 0 ); + } +} + +void test04() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + try { + throw 0; + } catch(...) { + exception_ptr ep1 = current_exception(); + try { + throw 0; + } catch(...) { + exception_ptr ep2 = current_exception(); + VERIFY( ep1 != ep2 ); + } + exception_ptr ep3 = current_exception(); + // Not guaranteed by standard, but by this implementation. + VERIFY( ep1 == ep3 ); + } +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc new file mode 100644 index 000000000..704f77e69 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/lifespan.cc @@ -0,0 +1,189 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at> + +// Copyright (C) 2008, 2009 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/>. + +// Tests the life span of the exception object. + +#include <exception> +#include <testsuite_hooks.h> + +bool may_destruct = false; + +class destructing +{ + mutable bool copied; + +public: + destructing() : copied(false) { } + destructing(const destructing &o) : copied(false) { o.copied = true; } + ~destructing() { VERIFY( copied || may_destruct ); } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + // Test the destructing class. + { + destructing *d = new destructing; + destructing d2(*d); + delete d; + may_destruct = true; + } + may_destruct = false; +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + try { + throw destructing(); + } catch(...) { + may_destruct = true; + } + may_destruct = false; +} + +void test03() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + try { + throw destructing(); + } catch(...) { + { + exception_ptr ep = current_exception(); + } + may_destruct = true; + } + may_destruct = false; +} + +void test04() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + { + exception_ptr ep; + try { + throw destructing(); + } catch(...) { + ep = current_exception(); + } + may_destruct = true; + } + may_destruct = false; +} + +void test05_helper() +{ + using namespace std; + try { + throw destructing(); + } catch(...) { + exception_ptr ep = current_exception(); + rethrow_exception(ep); + } +} + +void test05() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + try { + test05_helper(); + } catch(...) { + may_destruct = true; + } + may_destruct = false; +} + +void test06_helper() +{ + using namespace std; + try { + throw destructing(); + } catch(...) { + exception_ptr ep = current_exception(); + throw; + } +} + +void test06() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + try { + test06_helper(); + } catch(...) { + may_destruct = true; + } + may_destruct = false; +} + +std::exception_ptr gep; + +void test99() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + may_destruct = false; + + try { + throw destructing(); + } catch(...) { + gep = current_exception(); + } +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); + + test99(); + may_destruct = true; + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc new file mode 100644 index 000000000..4a7283f67 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/make_exception_ptr.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::exception_ptr p = std::make_exception_ptr(0); + + VERIFY( !(p == 0) ); +} + +int main() +{ + test01(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc new file mode 100644 index 000000000..ce97bc28c --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/move.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2009 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 <exception> +#include <utility> +#include <testsuite_hooks.h> + +// Verify move construction and assignment are efficient and do not copy. +// This behaviour is a GNU extension provided for efficiency. +void test01() +{ + bool test = true; + + std::exception_ptr p1 = std::copy_exception(test); + std::exception_ptr p2 = std::move(p1); + VERIFY( p1 == 0 ); + VERIFY( !(p2 == 0) ); + + p1 = std::move(p2); + VERIFY( !(p1 == 0) ); + VERIFY( p2 == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc new file mode 100644 index 000000000..36e6375d9 --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <exception> +#include <testsuite_hooks.h> + +// test NullablePointer requirements +void test01() +{ + std::exception_ptr p1; // DefaultConstructible + std::exception_ptr p2(p1); // CopyConstructible + p1 = p2; // CopyAssignable + VERIFY( p1 == p2 ); // EqualityComparable + VERIFY( !bool(p1) ); // contextually convertible to bool + swap(p1, p2); // Swappable + + // Table 39 expressions + std::exception_ptr p3 = nullptr; + std::exception_ptr p4(nullptr); + VERIFY( std::exception_ptr() == nullptr ); + p4 = nullptr; + VERIFY( p4 == nullptr ); + VERIFY( nullptr == p4 ); + VERIFY( (p4 != nullptr) == !(p4 == nullptr) ); + VERIFY( (nullptr != p4) == !(p4 == nullptr) ); + + std::exception_ptr p5{}; // value initialized ... + VERIFY( p5 == nullptr ); // ... is equivalent to null +} + +// additional exception_ptr requirements +void test02() +{ + std::exception_ptr p1; + VERIFY( p1 == nullptr ); +} + +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc new file mode 100644 index 000000000..b897b506d --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/requirements_neg.cc @@ -0,0 +1,33 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <exception> + +// test implicit conversions +void test01() +{ + std::exception_ptr p; + + int __attribute__((unused)) i = p; // { dg-error "cannot convert" } + bool __attribute__((unused)) b = p; // { dg-error "cannot convert" } + void* __attribute__((unused)) v = p; // { dg-error "cannot convert" } +} + diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc new file mode 100644 index 000000000..96b04a2bf --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/exception_ptr/rethrow_exception.cc @@ -0,0 +1,114 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-atomic-builtins "" } + +// 2008-05-25 Sebastian Redl <sebastian.redl@getdesigned.at> + +// Copyright (C) 2008, 2009 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/>. + +// rethrow_exception() and preservation of data + +#include <exception> +#include <typeinfo> +#include <cstring> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + try { + rethrow_exception(copy_exception(0)); + } catch(...) { + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + try { + rethrow_exception(copy_exception(runtime_error("test"))); + } catch(exception &e) { + VERIFY( typeid(e) == typeid(runtime_error) ); + VERIFY( strcmp(e.what(), "test") == 0 ); + } +} + +void test03() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + exception_ptr ep; + try { + throw 0; + } catch(...) { + ep = current_exception(); + } + try { + rethrow_exception(ep); + } catch(...) { + } +} + +void test04() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + // Weave the exceptions in an attempt to confuse the machinery. + try { + throw 0; + } catch(...) { + exception_ptr ep1 = current_exception(); + try { + throw 1; + } catch(...) { + exception_ptr ep2 = current_exception(); + try { + rethrow_exception(ep1); + } catch(...) { + try { + rethrow_exception(ep2); + } catch(...) { + try { + rethrow_exception(ep1); + } catch(...) { + } + try { + rethrow_exception(ep2); + } catch(...) { + } + } + } + } + } +} + +int main() +{ + test01(); + test02(); + test03(); + test04(); + + return 0; +} |