Clang Project

clang_source_code/test/SemaCXX/std-compare-cxx2a.cpp
1// Test diagnostics for ill-formed STL <compare> headers.
2
3// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -fsyntax-only -pedantic -verify -Wsign-compare -std=c++2a %s
4
5void compare_not_found_test() {
6  // expected-error@+1 {{cannot deduce return type of 'operator<=>' because type 'std::partial_ordering' was not found; include <compare>}}
7  (void)(0.0 <=> 42.123);
8}
9
10namespace std {
11inline namespace __1 {
12struct partial_ordering; // expected-note {{forward declaration}}
13}
14} // namespace std
15
16auto compare_incomplete_test() {
17  // expected-error@+1 {{incomplete type 'std::partial_ordering' where a complete type is required}}
18  return (-1.2 <=> 123.0);
19}
20
21namespace std {
22inline namespace __1 {
23struct partial_ordering {
24  unsigned value;
25};
26} // namespace __1
27} // namespace std
28
29auto missing_member_test() {
30  // expected-error@+1 {{standard library implementation of 'std::partial_ordering' is not supported; member 'equivalent' is missing}}
31  return (1.0 <=> 1.0);
32}
33
34namespace std {
35inline namespace __1 {
36struct strong_ordering {
37  long long value;
38  static const strong_ordering equivalent; // expected-note {{declared here}}
39};
40} // namespace __1
41} // namespace std
42
43auto test_non_constexpr_var() {
44  // expected-error@+1 {{standard library implementation of 'std::strong_ordering' is not supported; member 'equivalent' does not have expected form}}
45  return (1 <=> 0);
46}
47
48namespace std {
49inline namespace __1 {
50struct strong_equality {
51  char value = 0;
52  constexpr strong_equality() = default;
53  // non-trivial
54  constexpr strong_equality(strong_equality const &other) : value(other.value) {}
55};
56} // namespace __1
57} // namespace std
58
59struct Class {};
60using MemPtr = void (Class::*)(int);
61
62auto test_non_trivial(MemPtr LHS, MemPtr RHS) {
63  // expected-error@+1 {{standard library implementation of 'std::strong_equality' is not supported; the type is not trivially copyable}}
64  return LHS <=> RHS;
65}
66