133 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3// Check the following typo correction behavior:4// - multiple typos in a single member call chain are all diagnosed5// - no typos are diagnosed for multiple typos in an expression when not all6// typos can be corrected7 8class DeepClass9{10public:11 void trigger() const;12};13 14class Y15{16public:17 const DeepClass& getX() const { return m_deepInstance; }18private:19 DeepClass m_deepInstance;20 int m_n;21};22 23class Z24{25public:26 const Y& getY0() const { return m_y0; }27 const Y& getActiveY() const { return m_y0; }28 29private:30 Y m_y0;31 Y m_y1;32};33 34Z z_obj;35 36void testMultipleCorrections()37{38 z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'}}39 getM().40 triggee();41}42 43void testNoCorrections()44{45 z_obj.getY2(). // expected-error {{no member named 'getY2' in 'Z'}}46 getM().47 thisDoesntSeemToMakeSense();48}49 50struct C {};51struct D { int value; };52struct A {53 C get_me_a_C();54};55struct B {56 D get_me_a_D();57};58class Scope {59public:60 A make_an_A();61 B make_a_B();62};63 64Scope scope_obj;65 66int testDiscardedCorrections() {67 return scope_obj.make_an_E(). // expected-error {{no member named 'make_an_E' in 'Scope'}}68 get_me_a_Z().value;69}70 71class AmbiguousHelper {72public:73 int helpMe();74 int helpBe();75};76class Ambiguous {77public:78 int calculateA();79 int calculateB();80 81 AmbiguousHelper getHelp1();82 AmbiguousHelper getHelp2();83};84 85Ambiguous ambiguous_obj;86 87int testDirectAmbiguousCorrection() {88 return ambiguous_obj.calculateZ(); // expected-error {{no member named 'calculateZ' in 'Ambiguous'}}89}90 91int testRecursiveAmbiguousCorrection() {92 return ambiguous_obj.getHelp3(). // expected-error {{no member named 'getHelp3' in 'Ambiguous'}}93 helpCe();94}95 96 97class DeepAmbiguityHelper {98public:99 DeepAmbiguityHelper& help1();100 DeepAmbiguityHelper& help2();101 102 DeepAmbiguityHelper& methodA();103 DeepAmbiguityHelper& somethingMethodB();104 DeepAmbiguityHelper& functionC();105 DeepAmbiguityHelper& deepMethodD();106 DeepAmbiguityHelper& asDeepAsItGets();107};108 109DeepAmbiguityHelper deep_obj;110 111int testDeepAmbiguity() {112 deep_obj.113 methodB(). // expected-error {{no member named 'methodB' in 'DeepAmbiguityHelper'}}114 somethingMethodC().115 functionD().116 deepMethodD().117 help3().118 asDeepASItGet().119 functionE();120}121 122struct Dog {123 int age;124 int size;125};126 127int from_dog_years(int DogYears, int DogSize);128int get_dog_years() {129 struct Dog doggo;130 return from_dog_years(doggo.agee, //expected-error{{no member named 'agee' in 'Dog'}}131 doggo.sizee); //expected-error{{no member named 'sizee' in 'Dog'}}132}133