57 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <ratio>10//11// [ratio.general]/212// Throughout subclause [ratio], the names of template parameters are13// used to express type requirements. If a template parameter is named14// R1 or R2, and the template argument is not a specialization of the15// ratio template, the program is ill-formed.16 17#include <ratio>18 19struct invalid {20 static const int num = 1;21 static const int den = 1;22};23 24using valid = std::ratio<1, 1>;25 26namespace add {27using valid_valid = std::ratio_add<valid, valid>::type;28using invalid_valid =29 std::ratio_add<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}30using valid_invalid =31 std::ratio_add<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}32} // namespace add33 34namespace subtract {35using valid_valid = std::ratio_subtract<valid, valid>::type;36using invalid_valid =37 std::ratio_subtract<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}38using valid_invalid =39 std::ratio_subtract<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}40} // namespace subtract41 42namespace multiply {43using valid_valid = std::ratio_multiply<valid, valid>::type;44using invalid_valid =45 std::ratio_multiply<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}46using valid_invalid =47 std::ratio_multiply<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}48} // namespace multiply49 50namespace divide {51using valid_valid = std::ratio_divide<valid, valid>::type;52using invalid_valid =53 std::ratio_divide<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}54using valid_invalid =55 std::ratio_divide<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}56} // namespace divide57