]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/ratio/operations/47913.cc
re PR c++/59378 (Internal compiler error when using __builtin_shuffle in a template...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / ratio / operations / 47913.cc
1 // { dg-options "-std=gnu++0x" }
2 // { dg-require-cstdint "" }
3
4 // Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License
18 // along with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 #include <ratio>
22 #include <limits>
23 #include <testsuite_hooks.h>
24
25 // libstdc++/47913
26 void test01()
27 {
28 bool test __attribute__((unused)) = true;
29 using namespace std;
30
31 const intmax_t m1 = (intmax_t)1 << (4 * sizeof(intmax_t) - 1);
32 typedef ratio_add<ratio<1, (m1 - 1) * (m1 - 2)>,
33 ratio<1, (m1 - 3) * (m1 - 2)> > ra_type1;
34 VERIFY( ra_type1::num == 2 );
35 VERIFY( ra_type1::den == (m1 - 1) * (m1 - 3) );
36
37 const intmax_t m2 = numeric_limits<intmax_t>::max();
38 typedef ratio_add<ratio<m2, 2>,
39 ratio<-m2, 3> > ra_type2;
40 VERIFY( ra_type2::num == m2 );
41 VERIFY( ra_type2::den == 6 );
42
43 typedef ratio_add<ratio<m2 / 7 * 5 - 1, 5>,
44 ratio<-m2 + 2, 7> > ra_type3;
45 ra_type3();
46
47 const intmax_t m3 = numeric_limits<intmax_t>::max() - 1;
48 typedef ratio_add<ratio<-m3 / 7 * 5 - 1, 5>,
49 ratio<m3, 7> > ra_type4;
50 ra_type4();
51
52 const intmax_t m4 = numeric_limits<intmax_t>::max() / 2;
53 typedef ratio_add<ratio<m4 - 5, 15>,
54 ratio<m4, 35> > ra_type5;
55 VERIFY( ra_type5::num == (2 * m4 - 7) );
56 VERIFY( ra_type5::den == 21 );
57 }
58
59 int main()
60 {
61 test01();
62 return 0;
63 }