Debian Codegraph @

clang/test/SemaCXX/arrow-operator.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 struct T {
3 void f();
4 };
5
6 struct A {
7 T* operator->();
8 // expected-note@-1 {{member found by ambiguous name lookup}}
9 };
10
11 struct B {
12 T* operator->();
13 // expected-note@-1 {{member found by ambiguous name lookup}}
14 };
15
16 struct C : A, B {
17 };
18
19 struct D : A { };
20
21 struct E; // expected-note {{forward declaration of 'E'}}
22
23 void f(C &c, D& d, E& e) {
24 c->f();
25 // expected-error@-1 {{member 'operator->' found in multiple base classes of different types}}
26 d->f();
27 e->f(); // expected-error{{incomplete definition of type}}
28 }
29
30 namespace rdar8875304 {
31 class Point {};
32 class Line_Segment{ public: Line_Segment(const Point&){} };
33 class Node { public: Point Location(){ Point p; return p; } };
34
35 void f()
36 {
37 Node** node1;
38 Line_Segment(node1->Location()); // expected-error {{not a structure or union}}
39 }
40 }
41
42
43 namespace arrow_suggest {
44
45 template <typename T>
46 class wrapped_ptr {
47 public:
48 wrapped_ptr(T* ptr) : ptr_(ptr) {}
49 T* operator->() { return ptr_; }
50 void Check();
51 private:
52 T *ptr_;
53 };
54
55 class Worker {
56 public:
57 void DoSomething();
58 void Chuck();
59 };
60
61 void test() {
62 wrapped_ptr<Worker> worker(new Worker);
63 worker.DoSomething(); // expected-error {{no member named 'DoSomething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}}
64 worker.DoSamething(); // expected-error {{no member named 'DoSamething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'}}
65 worker.Chuck(); // expected-error {{no member named 'Chuck' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'}}
66 }
67
68 } // namespace arrow_suggest
69
70 namespace no_crash_dependent_type {
71
72 template <class T>
73 struct A {
74 void call();
75 A *operator->();
76 };
77
78 template <class T>
79 void foo() {
80 // The "requires an initializer" error seems unnecessary.
81 A<int> &x = blah[7]; // expected-error {{use of undeclared identifier 'blah'}} \
82 // expected-error {{requires an initializer}}
83 // x is dependent.
84 x->call();
85 }
86
87 void test() {
88 foo<int>(); // expected-note {{requested here}}
89 }
90
91 } // namespace no_crash_dependent_type
92
93 namespace clangd_issue_1073_no_crash_dependent_type {
94
95 template <typename T> struct Ptr {
96 T *operator->();
97 };
98
99 struct Struct {
100 int len;
101 };
102
103 template <int>
104 struct TemplateStruct {
105 Ptr<Struct> val(); // expected-note {{declared here}}
106 };
107
108 template <int I>
109 void templateFunc(const TemplateStruct<I> &ts) {
110 Ptr<Struct> ptr = ts.val(); // expected-error {{function is not marked const}}
111 auto foo = ptr->len;
112 }
113
114 template void templateFunc<0>(const TemplateStruct<0> &); // expected-note {{requested here}}
115
116 } // namespace clangd_issue_1073_no_crash_dependent_type