xref: /llvm-project/clang/test/SemaCXX/compare-function-pointer.cpp (revision ad14b5b008e2f643cb989ec645f12bf26a8659bb)
1 // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
2 
3 using fp0_t = void (*)();
4 using fp1_t = int (*)();
5 
6 extern fp0_t a, b;
7 extern fp1_t c;
8 
9 bool eq0 = a == b;
10 bool ne0 = a != b;
11 bool lt0 = a < b;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp0_t')}}
12 bool le0 = a <= b;  // expected-warning {{ordered comparison of function pointers}}
13 bool gt0 = a > b;   // expected-warning {{ordered comparison of function pointers}}
14 bool ge0 = a >= b;  // expected-warning {{ordered comparison of function pointers}}
15 auto tw0 = a <=> b; // expected-error {{ordered comparison of function pointers}}
16 
17 bool eq1 = a == c;  // expected-error {{comparison of distinct pointer types}}
18 bool ne1 = a != c;  // expected-error {{comparison of distinct pointer types}}
19 bool lt1 = a < c;   // expected-warning {{ordered comparison of function pointers ('fp0_t' (aka 'void (*)()') and 'fp1_t' (aka 'int (*)()'))}}
20                     // expected-error@-1 {{comparison of distinct pointer types}}
21 bool le1 = a <= c;  // expected-warning {{ordered comparison of function pointers}}
22                     // expected-error@-1 {{comparison of distinct pointer types}}
23 bool gt1 = a > c;   // expected-warning {{ordered comparison of function pointers}}
24                     // expected-error@-1 {{comparison of distinct pointer types}}
25 bool ge1 = a >= c;  // expected-warning {{ordered comparison of function pointers}}
26                     // expected-error@-1 {{comparison of distinct pointer types}}
27 auto tw1 = a <=> c; // expected-error {{ordered comparison of function pointers}}
28