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