xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/arrow-operator.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc struct T {
3f4a2713aSLionel Sambuc   void f();
4f4a2713aSLionel Sambuc };
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc struct A {
7f4a2713aSLionel Sambuc   T* operator->(); // expected-note{{candidate function}}
8f4a2713aSLionel Sambuc };
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc struct B {
11f4a2713aSLionel Sambuc   T* operator->(); // expected-note{{candidate function}}
12f4a2713aSLionel Sambuc };
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc struct C : A, B {
15f4a2713aSLionel Sambuc };
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc struct D : A { };
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc struct E; // expected-note {{forward declaration of 'E'}}
20f4a2713aSLionel Sambuc 
f(C & c,D & d,E & e)21f4a2713aSLionel Sambuc void f(C &c, D& d, E& e) {
22f4a2713aSLionel Sambuc   c->f(); // expected-error{{use of overloaded operator '->' is ambiguous}}
23f4a2713aSLionel Sambuc   d->f();
24f4a2713aSLionel Sambuc   e->f(); // expected-error{{incomplete definition of type}}
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc // rdar://8875304
28f4a2713aSLionel Sambuc namespace rdar8875304 {
29f4a2713aSLionel Sambuc class Point {};
Line_Segment(const Point &)30f4a2713aSLionel Sambuc class Line_Segment{ public: Line_Segment(const Point&){} };
Location()31f4a2713aSLionel Sambuc class Node { public: Point Location(){ Point p; return p; } };
32f4a2713aSLionel Sambuc 
f()33f4a2713aSLionel Sambuc void f()
34f4a2713aSLionel Sambuc {
35f4a2713aSLionel Sambuc    Node** node1;
36f4a2713aSLionel Sambuc    Line_Segment(node1->Location()); // expected-error {{not a structure or union}}
37f4a2713aSLionel Sambuc }
38f4a2713aSLionel Sambuc }
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc namespace arrow_suggest {
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc template <typename T>
44f4a2713aSLionel Sambuc class wrapped_ptr {
45f4a2713aSLionel Sambuc  public:
wrapped_ptr(T * ptr)46f4a2713aSLionel Sambuc   wrapped_ptr(T* ptr) : ptr_(ptr) {}
operator ->()47f4a2713aSLionel Sambuc   T* operator->() { return ptr_; }
48f4a2713aSLionel Sambuc   void Check(); // expected-note {{'Check' declared here}}
49f4a2713aSLionel Sambuc  private:
50f4a2713aSLionel Sambuc   T *ptr_;
51f4a2713aSLionel Sambuc };
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc class Worker {
54f4a2713aSLionel Sambuc  public:
55*0a6a1f1dSLionel Sambuc   void DoSomething(); // expected-note {{'DoSomething' declared here}}
56f4a2713aSLionel Sambuc   void Chuck();
57f4a2713aSLionel Sambuc };
58f4a2713aSLionel Sambuc 
test()59f4a2713aSLionel Sambuc void test() {
60f4a2713aSLionel Sambuc   wrapped_ptr<Worker> worker(new Worker);
61f4a2713aSLionel Sambuc   worker.DoSomething(); // expected-error {{no member named 'DoSomething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}}
62*0a6a1f1dSLionel Sambuc   worker.DoSamething(); // expected-error {{no member named 'DoSamething' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean to use '->' instead of '.'?}} \
63*0a6a1f1dSLionel Sambuc                         // expected-error {{no member named 'DoSamething' in 'arrow_suggest::Worker'; did you mean 'DoSomething'?}}
64f4a2713aSLionel Sambuc   worker.Chuck(); // expected-error {{no member named 'Chuck' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean 'Check'?}}
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc } // namespace arrow_suggest
68