OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc3/] [libstdc++-v3/] [testsuite/] [20_util/] [common_type/] [requirements/] [typedefs-1.cc] - Blame information for rev 516

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// { dg-options "-std=gnu++0x" }
2
//
3
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
//
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
//
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
#include <type_traits>
21
#include <testsuite_hooks.h>
22
 
23
#define JOIN( X, Y ) DO_JOIN( X, Y )
24
#define DO_JOIN( X, Y ) DO_JOIN2(X,Y)
25
#define DO_JOIN2( X, Y ) X##Y
26
 
27
#define COMMON_TYPE_TEST_1(type1, uid) \
28
  typedef common_type<type1>::type JOIN(test_t,uid); \
29
  VERIFY( (is_same<JOIN(test_t,uid), JOIN(test_t,uid)>::value) ); \
30
  typedef common_type<const type1>::type JOIN(test_t,JOIN(uid,c)); \
31
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,c)), \
32
                   JOIN(test_t,JOIN(uid,c))>::value) ); \
33
  typedef common_type<volatile type1>::type JOIN(test_t,JOIN(uid,v)); \
34
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,v)), \
35
                   JOIN(test_t,JOIN(uid,v))>::value) ); \
36
  typedef common_type<const volatile type1>::type JOIN(test_t,JOIN(uid,cv)); \
37
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,cv)), \
38
                   JOIN(test_t,JOIN(uid,cv))>::value) ); \
39
  typedef common_type<type1 &>::type JOIN(test_t,JOIN(uid,l)); \
40
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,l)), \
41
                   JOIN(test_t,JOIN(uid,l))>::value) ); \
42
  typedef common_type<const type1 &>::type JOIN(test_t,JOIN(uid,lc)); \
43
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,lc)), \
44
                   JOIN(test_t,JOIN(uid,lc))>::value) ); \
45
  typedef common_type<volatile type1 &>::type JOIN(test_t,JOIN(uid,lv)); \
46
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,lv)), \
47
                   JOIN(test_t,JOIN(uid,lv))>::value) ); \
48
  typedef common_type<const volatile type1 &>::type JOIN(test_t,JOIN(uid,lcv)); \
49
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,lcv)), \
50
                   JOIN(test_t,JOIN(uid,lcv))>::value) ); \
51
  typedef common_type<type1 &&>::type JOIN(test_t,JOIN(uid,r)); \
52
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,r)), \
53
                   JOIN(test_t,JOIN(uid,r))>::value) ); \
54
  typedef common_type<const type1 &&>::type JOIN(test_t,JOIN(uid,rc)); \
55
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,rc)), \
56
                   JOIN(test_t,JOIN(uid,rc))>::value) ); \
57
  typedef common_type<volatile type1 &&>::type JOIN(test_t,JOIN(uid,rv)); \
58
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,rv)), \
59
                   JOIN(test_t,JOIN(uid,rv))>::value) ); \
60
  typedef common_type<const volatile type1 &&>::type JOIN(test_t,JOIN(uid,rcv)); \
61
  VERIFY( (is_same<JOIN(test_t,JOIN(uid,rcv)), \
62
                   JOIN(test_t,JOIN(uid,rcv))>::value) )
63
 
64
struct A { };
65
struct B : A { };
66
 
67
void test01()
68
{
69
  bool test __attribute__((unused)) = true;
70
  using std::common_type;
71
  using std::is_same;
72
 
73
  // Positive tests.
74
  COMMON_TYPE_TEST_1(int, 1);
75
  COMMON_TYPE_TEST_1(double, 2);
76
  COMMON_TYPE_TEST_1(A, 3);
77
  COMMON_TYPE_TEST_1(B, 4);
78
}
79
 
80
#define COMMON_TYPE_TEST_2_IMPL(type1, type2, type3, uid) \
81
  typedef common_type<type1, type2>::type       JOIN(JOIN(test, uid),_t1); \
82
  typedef common_type<type2, type1>::type       JOIN(JOIN(test, uid),_t2); \
83
  VERIFY( (is_same<JOIN(JOIN(test, uid),_t1), type3>::value) ); \
84
  VERIFY( (is_same<JOIN(JOIN(test, uid),_t2), type3>::value) )
85
 
86
#define NO_CV
87
 
88
#define COMMON_TYPE_TEST_2(cv_qual, type1, type2, type3, uid) \
89
  COMMON_TYPE_TEST_2_IMPL(cv_qual type1, type2, type3, uid); \
90
  COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &, type2, type3, JOIN(uid,l)); \
91
  COMMON_TYPE_TEST_2_IMPL(cv_qual type1 &&, type2, type3, JOIN(uid,r))
92
 
93
#define COMMON_TYPE_TEST_ALL_2(type1, type2, type3, uid) \
94
  COMMON_TYPE_TEST_2(NO_CV, type1, type2, type3, uid); \
95
  COMMON_TYPE_TEST_2(const, type1, type2, type3, uid); \
96
  COMMON_TYPE_TEST_2(volatile, type1, type2, type3, uid); \
97
  COMMON_TYPE_TEST_2(const volatile, type1, type2, type3, uid)
98
 
99
void test02()
100
{
101
  bool test __attribute__((unused)) = true;
102
  using std::common_type;
103
  using std::is_same;
104
 
105
  COMMON_TYPE_TEST_ALL_2(int, int, int, 1);
106
  COMMON_TYPE_TEST_ALL_2(int, double, double, 2);
107
  COMMON_TYPE_TEST_2(NO_CV, A, A, A, 3);
108
  COMMON_TYPE_TEST_2(const, A, A, const A, 4);
109
  COMMON_TYPE_TEST_2(NO_CV, B, A, A, 5);
110
}
111
 
112
int main()
113
{
114
  test01();
115
  test02();
116
  return 0;
117
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.