Debian Codegraph @

libcxx/test/std/utilities/ratio/ratio.comparison/R1_R2_requirement.verify.cpp

raw
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <ratio>
10 //
11 // [ratio.general]/2
12 // Throughout subclause [ratio], the names of template parameters are
13 // used to express type requirements. If a template parameter is named
14 // R1 or R2, and the template argument is not a specialization of the
15 // ratio template, the program is ill-formed.
16 //
17 // Since all std::ratio_xxx_v variables use the same instantiation, only one
18 // error will be generated. These values are tested in a separate test.
19
20 #include <ratio>
21
22 struct invalid {
23 static const int num = 1;
24 static const int den = 1;
25 };
26
27 using valid = std::ratio<1, 1>;
28
29 namespace equal {
30 using valid_valid = std::ratio_equal<valid, valid>::type;
31 using invalid_valid =
32 std::ratio_equal<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
33 using valid_invalid =
34 std::ratio_equal<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
35 } // namespace equal
36
37 namespace not_equal {
38 using valid_valid = std::ratio_not_equal<valid, valid>::type;
39 using invalid_valid =
40 std::ratio_not_equal<invalid,
41 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
42 using valid_invalid =
43 std::ratio_not_equal<valid,
44 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
45 } // namespace not_equal
46
47 namespace less {
48 using valid_valid = std::ratio_less<valid, valid>::type;
49 using invalid_valid =
50 std::ratio_less<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
51 using valid_invalid =
52 std::ratio_less<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
53 } // namespace less
54
55 namespace less_equal {
56 using valid_valid = std::ratio_less_equal<valid, valid>::type;
57 using invalid_valid =
58 std::ratio_less_equal<invalid,
59 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
60 using valid_invalid =
61 std::ratio_less_equal<valid,
62 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
63 } // namespace less_equal
64
65 namespace greater {
66 using valid_valid = std::ratio_greater<valid, valid>::type;
67 using invalid_valid =
68 std::ratio_greater<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
69 using valid_invalid =
70 std::ratio_greater<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
71 } // namespace greater
72
73 namespace greater_equal {
74 using valid_valid = std::ratio_greater_equal<valid, valid>::type;
75 using invalid_valid =
76 std::ratio_greater_equal<invalid,
77 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
78 using valid_invalid =
79 std::ratio_greater_equal<valid,
80 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
81 } // namespace greater_equal