diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-11-20 22:32:11 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-11-20 22:32:11 +0000 |
commit | 3ef3e899a9f0a640f179a4d50f1e8ab31b419fbb (patch) | |
tree | cff91cac381915b93673b27d78c4b5a3ac5834ea /clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp | |
parent | 8489349fdca5fe57991bf6c683fd20c02301b0e0 (diff) | |
download | bcm5719-llvm-3ef3e899a9f0a640f179a4d50f1e8ab31b419fbb.tar.gz bcm5719-llvm-3ef3e899a9f0a640f179a4d50f1e8ab31b419fbb.zip |
PR21565: Further refine the conditions for enabling eager parsing of
std::X::swap exception specifications (allowing parsing of non-conforming code
in libstdc++). The old conditions also matched the functions in MSVC's STL,
which were relying on deferred parsing here.
llvm-svn: 222471
Diffstat (limited to 'clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp')
-rw-r--r-- | clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp b/clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp index 8c7c782c32b..02431e02e48 100644 --- a/clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp +++ b/clang/test/SemaCXX/libstdcxx_pair_swap_hack.cpp @@ -1,20 +1,47 @@ -// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions - // This is a test for an egregious hack in Clang that works around // an issue with GCC's <utility> implementation. std::pair::swap // has an exception specification that makes an unqualified call to // swap. This is invalid, because it ends up calling itself with // the wrong number of arguments. +// +// The same problem afflicts a bunch of other class templates. Those +// affected are array, pair, priority_queue, stack, and queue. + +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=pair +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=priority_queue +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=stack +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=queue + +// MSVC's standard library uses a very similar pattern that relies on delayed +// parsing of exception specifications. +// +// RUN: %clang_cc1 -fsyntax-only %s -std=c++11 -verify -fexceptions -fcxx-exceptions -DCLASS=array -DMSVC #ifdef BE_THE_HEADER #pragma GCC system_header namespace std { template<typename T> void swap(T &, T &); + template<typename T> void do_swap(T &a, T &b) noexcept(noexcept(swap(a, b))) { + swap(a, b); + } - template<typename A, typename B> struct pair { - void swap(pair &other) noexcept(noexcept(swap(*this, other))); + template<typename A, typename B> struct CLASS { +#ifdef MSVC + void swap(CLASS &other) noexcept(noexcept(do_swap(member, other.member))); +#endif + A member; +#ifndef MSVC + void swap(CLASS &other) noexcept(noexcept(swap(member, other.member))); +#endif }; + +// template<typename T> void do_swap(T &, T &); +// template<typename A> struct vector { +// void swap(vector &other) noexcept(noexcept(do_swap(member, other.member))); +// A member; +// }; } #else @@ -23,9 +50,9 @@ namespace std { #include __FILE__ struct X {}; -using PX = std::pair<X, X>; -using PI = std::pair<int, int>; -void swap(PX &, PX &) noexcept; +using PX = std::CLASS<X, X>; +using PI = std::CLASS<int, int>; +void swap(X &, X &) noexcept; PX px; PI pi; @@ -35,11 +62,11 @@ static_assert(!noexcept(pi.swap(pi)), ""); namespace sad { template<typename T> void swap(T &, T &); - template<typename A, typename B> struct pair { - void swap(pair &other) noexcept(noexcept(swap(*this, other))); // expected-error {{too many arguments}} expected-note {{declared here}} + template<typename A, typename B> struct CLASS { + void swap(CLASS &other) noexcept(noexcept(swap(*this, other))); // expected-error {{too many arguments}} expected-note {{declared here}} }; - pair<int, int> pi; + CLASS<int, int> pi; static_assert(!noexcept(pi.swap(pi)), ""); // expected-note {{in instantiation of}} } |