Debian Codegraph @

clang/test/SemaCXX/PR172001.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -verify=test1 -DTEST1 %s
2 // RUN: %clang_cc1 -std=c++20 -verify=test2 -DTEST2 %s
3 // RUN: %clang_cc1 -std=c++20 -verify=test3 -DTEST3 %s
4 // RUN: %clang_cc1 -std=c++20 -verify=test4 -DTEST4 %s
5 // RUN: %clang_cc1 -std=c++20 -verify=test5 -DTEST5 %s
6
7 namespace std {
8 #ifdef TEST1
9 // Case 1: Malformed struct (static members are wrong type)
10 // This triggered the original crash (GH170015).
11 struct partial_ordering {
12 static constexpr int equivalent = 0;
13 static constexpr int less = -1;
14 static constexpr int greater = 1;
15 static constexpr int unordered = 2;
16 };
17 #elif defined(TEST2)
18 // Case 2: partial_ordering is a typedef to int
19 using partial_ordering = int;
20 #elif defined(TEST3)
21 // Case 3: partial_ordering is a forward declaration
22 struct partial_ordering; // test3-note {{forward declaration of 'std::partial_ordering'}}
23 #elif defined(TEST4)
24 // Case 4: partial_ordering is a template (Paranoia check)
25 template <class> struct partial_ordering {
26 static const partial_ordering less;
27 static const partial_ordering equivalent;
28 static const partial_ordering greater;
29 static const partial_ordering unordered;
30 };
31 #elif defined(TEST5)
32 // Case 5: strong_ordering is a typedef to int (covers GH56571)
33 using strong_ordering = int;
34 #endif
35 }
36
37 void f() {
38 #ifdef TEST5
39 int a = 0, b = 0; // int <=> int requires std::strong_ordering
40 #else
41 float a = 0.0f, b = 0.0f; // float <=> float requires std::partial_ordering
42 #endif
43
44 auto res = a <=> b;
45
46 // test1-error@-2 {{standard library implementation of 'std::partial_ordering' is not supported; the type does not have the expected form}}
47 // test2-error@-3 {{cannot use builtin operator '<=>' because type 'std::partial_ordering' was not found; include <compare>}}
48 // test3-error@-4 {{incomplete type 'std::partial_ordering' where a complete type is required}}
49 // test4-error@-5 {{cannot use builtin operator '<=>' because type 'std::partial_ordering' was not found; include <compare>}}
50 // test5-error@-6 {{cannot use builtin operator '<=>' because type 'std::strong_ordering' was not found; include <compare>}}
51 }