summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/common_type
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/20_util/common_type
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/20_util/common_type')
-rw-r--r--libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc41
-rw-r--r--libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc117
-rw-r--r--libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc72
3 files changed, 230 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc
new file mode 100644
index 000000000..93422ca84
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/explicit_instantiation.cc
@@ -0,0 +1,41 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// 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/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+ typedef int test_type1;
+ typedef int& test_type2;
+ typedef double test_type3;
+ typedef float test_type4;
+ typedef void test_type5;
+ typedef const void test_type6;
+
+ template struct common_type<test_type1>;
+ template struct common_type<test_type1, test_type2>;
+ template struct common_type<test_type1, test_type2, test_type3>;
+ template struct common_type<test_type1, test_type2, test_type3, test_type4>;
+
+ template struct common_type<test_type5>;
+ template struct common_type<test_type5, test_type6>;
+}
diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc
new file mode 100644
index 000000000..94469d974
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-1.cc
@@ -0,0 +1,117 @@
+// { dg-options "-std=gnu++0x" }
+//
+// 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/>.
+
+#include <type_traits>
+#include <testsuite_hooks.h>
+
+#define JOIN( X, Y ) DO_JOIN( X, Y )
+#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
+#define DO_JOIN2( X, Y ) X##Y
+
+#define COMMON_TYPE_TEST_1(type1, uid) \
+ typedef common_type<type1>::type JOIN(test_t,uid); \
+ VERIFY( (is_same<JOIN(test_t,uid), JOIN(test_t,uid)>::value) ); \
+ typedef common_type<const type1>::type JOIN(test_t,JOIN(uid,c)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,c)), \
+ JOIN(test_t,JOIN(uid,c))>::value) ); \
+ typedef common_type<volatile type1>::type JOIN(test_t,JOIN(uid,v)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,v)), \
+ JOIN(test_t,JOIN(uid,v))>::value) ); \
+ typedef common_type<const volatile type1>::type JOIN(test_t,JOIN(uid,cv)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,cv)), \
+ JOIN(test_t,JOIN(uid,cv))>::value) ); \
+ typedef common_type<type1 &>::type JOIN(test_t,JOIN(uid,l)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,l)), \
+ JOIN(test_t,JOIN(uid,l))>::value) ); \
+ typedef common_type<const type1 &>::type JOIN(test_t,JOIN(uid,lc)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,lc)), \
+ JOIN(test_t,JOIN(uid,lc))>::value) ); \
+ typedef common_type<volatile type1 &>::type JOIN(test_t,JOIN(uid,lv)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,lv)), \
+ JOIN(test_t,JOIN(uid,lv))>::value) ); \
+ typedef common_type<const volatile type1 &>::type JOIN(test_t,JOIN(uid,lcv)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,lcv)), \
+ JOIN(test_t,JOIN(uid,lcv))>::value) ); \
+ typedef common_type<type1 &&>::type JOIN(test_t,JOIN(uid,r)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,r)), \
+ JOIN(test_t,JOIN(uid,r))>::value) ); \
+ typedef common_type<const type1 &&>::type JOIN(test_t,JOIN(uid,rc)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,rc)), \
+ JOIN(test_t,JOIN(uid,rc))>::value) ); \
+ typedef common_type<volatile type1 &&>::type JOIN(test_t,JOIN(uid,rv)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,rv)), \
+ JOIN(test_t,JOIN(uid,rv))>::value) ); \
+ typedef common_type<const volatile type1 &&>::type JOIN(test_t,JOIN(uid,rcv)); \
+ VERIFY( (is_same<JOIN(test_t,JOIN(uid,rcv)), \
+ JOIN(test_t,JOIN(uid,rcv))>::value) )
+
+struct A { };
+struct B : A { };
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::common_type;
+ using std::is_same;
+
+ // Positive tests.
+ COMMON_TYPE_TEST_1(int, 1);
+ COMMON_TYPE_TEST_1(double, 2);
+ COMMON_TYPE_TEST_1(A, 3);
+ COMMON_TYPE_TEST_1(B, 4);
+}
+
+#define COMMON_TYPE_TEST_2_IMPL(type1, type2, type3, uid) \
+ typedef common_type<type1, type2>::type JOIN(JOIN(test, uid),_t1); \
+ typedef common_type<type2, type1>::type JOIN(JOIN(test, uid),_t2); \
+ VERIFY( (is_same<JOIN(JOIN(test, uid),_t1), type3>::value) ); \
+ VERIFY( (is_same<JOIN(JOIN(test, uid),_t2), type3>::value) )
+
+#define NO_CV
+
+#define COMMON_TYPE_TEST_2(cv_qual, type1, type2, type3, uid) \
+ COMMON_TYPE_TEST_2_IMPL(cv_qual type1, type2, type3, uid); \
+ COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &, type2, type3, JOIN(uid,l)); \
+ COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &&, type2, type3, JOIN(uid,r))
+
+#define COMMON_TYPE_TEST_ALL_2(type1, type2, type3, uid) \
+ COMMON_TYPE_TEST_2(NO_CV, type1, type2, type3, uid); \
+ COMMON_TYPE_TEST_2(const, type1, type2, type3, uid); \
+ COMMON_TYPE_TEST_2(volatile, type1, type2, type3, uid); \
+ COMMON_TYPE_TEST_2(const volatile, type1, type2, type3, uid)
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using std::common_type;
+ using std::is_same;
+
+ COMMON_TYPE_TEST_ALL_2(int, int, int, 1);
+ COMMON_TYPE_TEST_ALL_2(int, double, double, 2);
+ COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3);
+ COMMON_TYPE_TEST_2(const, A, A, const A, 4);
+ COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5);
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc
new file mode 100644
index 000000000..b4a96e540
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/common_type/requirements/typedefs-2.cc
@@ -0,0 +1,72 @@
+// { dg-options "-std=gnu++0x" }
+// 2009-11-12 Paolo Carlini <paolo.carlini@oracle.com>
+//
+// 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 <type_traits>
+#include <testsuite_hooks.h>
+
+// DR 1255.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using std::common_type;
+ using std::is_same;
+
+ VERIFY( (is_same<common_type<void>::type, void>::value) );
+ VERIFY( (is_same<common_type<const void>::type, const void>::value) );
+ VERIFY( (is_same<common_type<volatile void>::type, volatile void>::value) );
+ VERIFY( (is_same<common_type<const volatile void>::type,
+ const volatile void>::value) );
+
+ VERIFY( (is_same<common_type<void, void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, const void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, volatile void>::type, void>::value) );
+ VERIFY( (is_same<common_type<void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<volatile void, const volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, const void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, volatile void>::type,
+ void>::value) );
+ VERIFY( (is_same<common_type<const volatile void, const volatile void>::type,
+ void>::value) );
+ }
+
+int main()
+{
+ test01();
+ return 0;
+}