[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / arrow-operator.cpp
blob295dea3c1756cb28fe4306d51d2deb598503c517
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 struct T {
3 void f();
4 };
6 struct A {
7 T* operator->();
8 // expected-note@-1 {{member found by ambiguous name lookup}}
9 };
11 struct B {
12 T* operator->();
13 // expected-note@-1 {{member found by ambiguous name lookup}}
16 struct C : A, B {
19 struct D : A { };
21 struct E; // expected-note {{forward declaration of 'E'}}
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}}
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; } };
35 void f()
37 Node** node1;
38 Line_Segment(node1->Location()); // expected-error {{not a structure or union}}
43 namespace arrow_suggest {
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(); // expected-note {{'Check' declared here}}
51 private:
52 T *ptr_;
55 class Worker {
56 public:
57 void DoSomething(); // expected-note {{'DoSomething' declared here}}
58 void Chuck();
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>'; did you mean to use '->' instead of '.'?}} \
65 // expected-error {{no member named 'DoSamething' in 'arrow_suggest::Worker'; did you mean 'DoSomething'?}}
66 worker.Chuck(); // expected-error {{no member named 'Chuck' in 'arrow_suggest::wrapped_ptr<arrow_suggest::Worker>'; did you mean 'Check'?}}
69 } // namespace arrow_suggest
71 namespace no_crash_dependent_type {
73 template <class T>
74 struct A {
75 void call();
76 A *operator->();
79 template <class T>
80 void foo() {
81 // The "requires an initializer" error seems unnecessary.
82 A<int> &x = blah[7]; // expected-error {{use of undeclared identifier 'blah'}} \
83 // expected-error {{requires an initializer}}
84 // x is dependent.
85 x->call();
88 void test() {
89 foo<int>(); // expected-note {{requested here}}
92 } // namespace no_crash_dependent_type
94 namespace clangd_issue_1073_no_crash_dependent_type {
96 template <typename T> struct Ptr {
97 T *operator->();
100 struct Struct {
101 int len;
104 template <int>
105 struct TemplateStruct {
106 Ptr<Struct> val(); // expected-note {{declared here}}
109 template <int I>
110 void templateFunc(const TemplateStruct<I> &ts) {
111 Ptr<Struct> ptr = ts.val(); // expected-error {{function is not marked const}}
112 auto foo = ptr->len;
115 template void templateFunc<0>(const TemplateStruct<0> &); // expected-note {{requested here}}
117 } // namespace clangd_issue_1073_no_crash_dependent_type