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// UNSUPPORTED: c++03, c++11, c++14
10
11// <ratio>
12//
13// [ratio.general]/2
14// Throughout subclause [ratio], the names of template parameters are
15// used to express type requirements. If a template parameter is named
16// R1 or R2, and the template argument is not a specialization of the
17// ratio template, the program is ill-formed.
18//
19// Since all std::ratio_xxx_v variables use the same instantiation, only one
20// error will be generated. These values are tested in a separate test.
21
22#include <ratio>
23
24struct invalid {
25 constexpr static int num = 1;
26 constexpr static int den = 1;
27};
28
29using valid = std::ratio<1, 1>;
30
31void test() {
32 // equal
33 (void)std::ratio_equal_v<valid, valid>;
34 (void)std::ratio_equal_v<invalid, valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
35 (void)std::ratio_equal_v<valid, invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
36
37 // not_equal
38 (void)std::ratio_not_equal_v<valid, valid>;
39 (void)std::ratio_not_equal_v<invalid,
40 valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
41 (void)std::ratio_not_equal_v<valid,
42 invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
43
44 // less
45 (void)std::ratio_less_v<valid, valid>;
46 (void)std::ratio_less_v<invalid, valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
47 (void)std::ratio_less_v<valid, invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
48
49 // less_equal
50 (void)std::ratio_less_equal_v<valid, valid>;
51 (void)std::ratio_less_equal_v<invalid,
52 valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
53 (void)std::ratio_less_equal_v<valid,
54 invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
55
56 // greater
57 (void)std::ratio_greater_v<valid, valid>;
58 (void)std::ratio_greater_v<invalid, valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
59 (void)std::ratio_greater_v<valid, invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
60
61 // greater_equal
62 (void)std::ratio_greater_equal_v<valid, valid>;
63
64 (void)std::ratio_greater_equal_v<invalid,
65 valid>; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
66
67 (void)std::ratio_greater_equal_v<valid,
68 invalid>; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
69}
70

source code of libcxx/test/std/utilities/ratio/ratio.comparison/R1_R2_requirement_v.verify.cpp