xref: /llvm-project/libcxx/test/std/utilities/ratio/ratio.arithmetic/R1_R2_requirement.verify.cpp (revision fe0d277f31d3369de1fd92ad8dd8044f5b1d4ed7)
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 #include <ratio>
18 
19 struct invalid {
20   static const int num = 1;
21   static const int den = 1;
22 };
23 
24 using valid = std::ratio<1, 1>;
25 
26 namespace add {
27 using valid_valid = std::ratio_add<valid, valid>::type;
28 using invalid_valid =
29     std::ratio_add<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
30 using valid_invalid =
31     std::ratio_add<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
32 } // namespace add
33 
34 namespace subtract {
35 using valid_valid = std::ratio_subtract<valid, valid>::type;
36 using invalid_valid =
37     std::ratio_subtract<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
38 using valid_invalid =
39     std::ratio_subtract<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
40 } // namespace subtract
41 
42 namespace multiply {
43 using valid_valid = std::ratio_multiply<valid, valid>::type;
44 using invalid_valid =
45     std::ratio_multiply<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
46 using valid_invalid =
47     std::ratio_multiply<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
48 } // namespace multiply
49 
50 namespace divide {
51 using valid_valid = std::ratio_divide<valid, valid>::type;
52 using invalid_valid =
53     std::ratio_divide<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
54 using valid_invalid =
55     std::ratio_divide<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
56 } // namespace divide
57