Douglas Gregor | 546be3c | 2009-12-30 17:04:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 2 | // RUN: cp %s %t |
Douglas Gregor | 27766d2 | 2011-04-27 03:47:06 +0000 | [diff] [blame] | 3 | // RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t |
Nick Lewycky | ba5f6ec | 2010-04-24 01:30:46 +0000 | [diff] [blame] | 4 | // RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t |
Douglas Gregor | 27766d2 | 2011-04-27 03:47:06 +0000 | [diff] [blame] | 5 | // RUN: grep test_string %t |
Douglas Gregor | 9a632ea | 2010-10-20 03:06:34 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | 546be3c | 2009-12-30 17:04:44 +0000 | [diff] [blame] | 7 | namespace std { |
Kaelyn Uhrain | b2567dd | 2013-07-02 23:47:44 +0000 | [diff] [blame] | 8 | template<typename T> class basic_string { // expected-note 3{{'basic_string' declared here}} |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 9 | public: |
Douglas Gregor | 67dd1d4 | 2010-01-07 00:17:44 +0000 | [diff] [blame] | 10 | int find(const char *substr); // expected-note{{'find' declared here}} |
| 11 | static const int npos = -1; // expected-note{{'npos' declared here}} |
Douglas Gregor | bb092ba | 2009-12-31 05:20:13 +0000 | [diff] [blame] | 12 | }; |
| 13 | |
Douglas Gregor | 67dd1d4 | 2010-01-07 00:17:44 +0000 | [diff] [blame] | 14 | typedef basic_string<char> string; // expected-note 2{{'string' declared here}} |
Douglas Gregor | 546be3c | 2009-12-30 17:04:44 +0000 | [diff] [blame] | 15 | } |
| 16 | |
Douglas Gregor | 6699220 | 2010-06-29 17:53:46 +0000 | [diff] [blame] | 17 | namespace otherstd { // expected-note 2{{'otherstd' declared here}} \ |
Douglas Gregor | ed84076 | 2010-06-29 19:17:14 +0000 | [diff] [blame] | 18 | // expected-note{{namespace 'otherstd' defined here}} |
Douglas Gregor | 546be3c | 2009-12-30 17:04:44 +0000 | [diff] [blame] | 19 | using namespace std; |
| 20 | } |
| 21 | |
| 22 | using namespace std; |
| 23 | |
Douglas Gregor | 175a656 | 2009-12-31 08:26:35 +0000 | [diff] [blame] | 24 | other_std::strng str1; // expected-error{{use of undeclared identifier 'other_std'; did you mean 'otherstd'?}} \ |
| 25 | // expected-error{{no type named 'strng' in namespace 'otherstd'; did you mean 'string'?}} |
Douglas Gregor | 546be3c | 2009-12-30 17:04:44 +0000 | [diff] [blame] | 26 | tring str2; // expected-error{{unknown type name 'tring'; did you mean 'string'?}} |
Douglas Gregor | bb092ba | 2009-12-31 05:20:13 +0000 | [diff] [blame] | 27 | |
Douglas Gregor | 6c409a0 | 2009-12-31 08:27:32 +0000 | [diff] [blame] | 28 | ::other_std::string str3; // expected-error{{no member named 'other_std' in the global namespace; did you mean 'otherstd'?}} |
| 29 | |
Douglas Gregor | 539c5c3 | 2010-01-07 00:31:29 +0000 | [diff] [blame] | 30 | float area(float radius, // expected-note{{'radius' declared here}} |
| 31 | float pi) { |
| 32 | return radious * pi; // expected-error{{did you mean 'radius'?}} |
Douglas Gregor | bb092ba | 2009-12-31 05:20:13 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Douglas Gregor | 6699220 | 2010-06-29 17:53:46 +0000 | [diff] [blame] | 35 | using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}} |
Douglas Gregor | ed84076 | 2010-06-29 19:17:14 +0000 | [diff] [blame] | 36 | namespace blargh = otherstd; // expected-note 3{{namespace 'blargh' defined here}} |
Douglas Gregor | 6699220 | 2010-06-29 17:53:46 +0000 | [diff] [blame] | 37 | using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} |
| 38 | |
Douglas Gregor | 0e8c4b9 | 2010-06-29 18:55:19 +0000 | [diff] [blame] | 39 | namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}} |
| 40 | namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}} |
| 41 | |
Douglas Gregor | bb092ba | 2009-12-31 05:20:13 +0000 | [diff] [blame] | 42 | bool test_string(std::string s) { |
Douglas Gregor | bfea239 | 2009-12-31 08:11:17 +0000 | [diff] [blame] | 43 | basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}} |
| 44 | std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}} |
| 45 | (void)b1; |
| 46 | (void)b2; |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 47 | return s.fnd("hello") // expected-error{{no member named 'fnd' in 'std::basic_string<char>'; did you mean 'find'?}} |
| 48 | == std::string::pos; // expected-error{{no member named 'pos' in 'std::basic_string<char>'; did you mean 'npos'?}} |
Douglas Gregor | bb092ba | 2009-12-31 05:20:13 +0000 | [diff] [blame] | 49 | } |
Douglas Gregor | fe0241e | 2009-12-31 09:10:24 +0000 | [diff] [blame] | 50 | |
| 51 | struct Base { }; |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 52 | struct Derived : public Base { // expected-note{{base class 'Base' specified here}} |
Douglas Gregor | 67dd1d4 | 2010-01-07 00:17:44 +0000 | [diff] [blame] | 53 | int member; // expected-note 3{{'member' declared here}} |
Douglas Gregor | fe0241e | 2009-12-31 09:10:24 +0000 | [diff] [blame] | 54 | |
| 55 | Derived() : base(), // expected-error{{initializer 'base' does not name a non-static data member or base class; did you mean the base class 'Base'?}} |
| 56 | ember() { } // expected-error{{initializer 'ember' does not name a non-static data member or base class; did you mean the member 'member'?}} |
Douglas Gregor | e358201 | 2010-01-01 17:44:25 +0000 | [diff] [blame] | 57 | |
| 58 | int getMember() const { |
| 59 | return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}} |
| 60 | } |
| 61 | |
| 62 | int &getMember(); |
Douglas Gregor | fe0241e | 2009-12-31 09:10:24 +0000 | [diff] [blame] | 63 | }; |
Douglas Gregor | e358201 | 2010-01-01 17:44:25 +0000 | [diff] [blame] | 64 | |
| 65 | int &Derived::getMember() { |
| 66 | return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}} |
| 67 | } |
Douglas Gregor | 3b88735 | 2011-04-27 04:48:22 +0000 | [diff] [blame] | 68 | |
| 69 | typedef int Integer; // expected-note{{'Integer' declared here}} |
| 70 | int global_value; // expected-note{{'global_value' declared here}} |
| 71 | |
| 72 | int foo() { |
| 73 | integer * i = 0; // expected-error{{unknown type name 'integer'; did you mean 'Integer'?}} |
| 74 | unsinged *ptr = 0; // expected-error{{use of undeclared identifier 'unsinged'; did you mean 'unsigned'?}} |
| 75 | return *i + *ptr + global_val; // expected-error{{use of undeclared identifier 'global_val'; did you mean 'global_value'?}} |
| 76 | } |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 77 | |
| 78 | namespace nonstd { |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 79 | typedef std::basic_string<char> yarn; // expected-note 2 {{'nonstd::yarn' declared here}} |
| 80 | int narf; // expected-note{{'nonstd::narf' declared here}} |
Douglas Gregor | d8bba9c | 2011-06-28 16:20:02 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | yarn str4; // expected-error{{unknown type name 'yarn'; did you mean 'nonstd::yarn'?}} |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 84 | wibble::yarn str5; // expected-error{{no type named 'yarn' in namespace 'otherstd'; did you mean 'nonstd::yarn'?}} |
| 85 | |
Kaelyn Uhrain | 8d90b4a | 2013-06-24 17:49:03 +0000 | [diff] [blame] | 86 | namespace another { |
| 87 | template<typename T> class wide_string {}; // expected-note {{'another::wide_string' declared here}} |
| 88 | } |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 89 | int poit() { |
Kaelyn Uhrain | b2567dd | 2013-07-02 23:47:44 +0000 | [diff] [blame] | 90 | nonstd::basic_string<char> str; // expected-error{{no template named 'basic_string' in namespace 'nonstd'; did you mean simply 'basic_string'?}} |
Kaelyn Uhrain | 8d90b4a | 2013-06-24 17:49:03 +0000 | [diff] [blame] | 91 | nonstd::wide_string<char> str2; // expected-error{{no template named 'wide_string' in namespace 'nonstd'; did you mean 'another::wide_string'?}} |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 92 | return wibble::narf; // expected-error{{no member named 'narf' in namespace 'otherstd'; did you mean 'nonstd::narf'?}} |
| 93 | } |
Douglas Gregor | 07f4a06 | 2011-07-01 21:27:45 +0000 | [diff] [blame] | 94 | |
| 95 | namespace check_bool { |
| 96 | void f() { |
| 97 | Bool b; // expected-error{{use of undeclared identifier 'Bool'; did you mean 'bool'?}} |
| 98 | } |
| 99 | } |
David Blaikie | 6952c01 | 2012-10-12 20:00:44 +0000 | [diff] [blame] | 100 | |
| 101 | namespace outr { |
| 102 | } |
| 103 | namespace outer { |
| 104 | namespace inner { // expected-note{{'outer::inner' declared here}} \ |
| 105 | // expected-note{{namespace 'outer::inner' defined here}} \ |
| 106 | // expected-note{{'inner' declared here}} |
| 107 | int i; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | using namespace outr::inner; // expected-error{{no namespace named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}} |
| 112 | |
| 113 | void func() { |
| 114 | outr::inner::i = 3; // expected-error{{no member named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}} |
| 115 | outer::innr::i = 4; // expected-error{{no member named 'innr' in namespace 'outer'; did you mean 'inner'?}} |
| 116 | } |
| 117 | |
| 118 | struct base { |
| 119 | }; |
| 120 | struct derived : base { |
| 121 | int i; |
| 122 | }; |
| 123 | |
| 124 | void func2() { |
| 125 | derived d; |
| 126 | // FIXME: we should offer a fix here. We do if the 'i' is misspelled, but we don't do name qualification changes |
| 127 | // to replace base::i with derived::i as we would for other qualified name misspellings. |
| 128 | // d.base::i = 3; |
| 129 | } |
Kaelyn Uhrain | 6c4898b | 2013-07-08 23:13:44 +0000 | [diff] [blame] | 130 | |
| 131 | class A { |
| 132 | void bar(int); |
| 133 | }; |
| 134 | void bar(int, int); // expected-note{{'::bar' declared here}} |
| 135 | void A::bar(int x) { |
| 136 | bar(x, 5); // expected-error{{too many arguments to function call, expected 1, have 2; did you mean '::bar'?}} |
| 137 | } |