blob: 3d40da8d256a17abbf5550adac3db3643e1de05a [file] [log] [blame]
Douglas Gregor546be3c2009-12-30 17:04:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00002// RUN: cp %s %t
Douglas Gregor27766d22011-04-27 03:47:06 +00003// RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t
Nick Lewyckyba5f6ec2010-04-24 01:30:46 +00004// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t
Douglas Gregor27766d22011-04-27 03:47:06 +00005// RUN: grep test_string %t
Douglas Gregor9a632ea2010-10-20 03:06:34 +00006
Douglas Gregor546be3c2009-12-30 17:04:44 +00007namespace std {
Douglas Gregor67dd1d42010-01-07 00:17:44 +00008 template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}}
John McCall7002f4c2010-04-09 19:03:51 +00009 public:
Douglas Gregor67dd1d42010-01-07 00:17:44 +000010 int find(const char *substr); // expected-note{{'find' declared here}}
11 static const int npos = -1; // expected-note{{'npos' declared here}}
Douglas Gregorbb092ba2009-12-31 05:20:13 +000012 };
13
Douglas Gregor67dd1d42010-01-07 00:17:44 +000014 typedef basic_string<char> string; // expected-note 2{{'string' declared here}}
Douglas Gregor546be3c2009-12-30 17:04:44 +000015}
16
Douglas Gregor66992202010-06-29 17:53:46 +000017namespace otherstd { // expected-note 2{{'otherstd' declared here}} \
Douglas Gregored840762010-06-29 19:17:14 +000018 // expected-note{{namespace 'otherstd' defined here}}
Douglas Gregor546be3c2009-12-30 17:04:44 +000019 using namespace std;
20}
21
22using namespace std;
23
Douglas Gregor175a6562009-12-31 08:26:35 +000024other_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 Gregor546be3c2009-12-30 17:04:44 +000026tring str2; // expected-error{{unknown type name 'tring'; did you mean 'string'?}}
Douglas Gregorbb092ba2009-12-31 05:20:13 +000027
Douglas Gregor6c409a02009-12-31 08:27:32 +000028::other_std::string str3; // expected-error{{no member named 'other_std' in the global namespace; did you mean 'otherstd'?}}
29
Douglas Gregor539c5c32010-01-07 00:31:29 +000030float area(float radius, // expected-note{{'radius' declared here}}
31 float pi) {
32 return radious * pi; // expected-error{{did you mean 'radius'?}}
Douglas Gregorbb092ba2009-12-31 05:20:13 +000033}
34
Douglas Gregor66992202010-06-29 17:53:46 +000035using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}}
Douglas Gregored840762010-06-29 19:17:14 +000036namespace blargh = otherstd; // expected-note 3{{namespace 'blargh' defined here}}
Douglas Gregor66992202010-06-29 17:53:46 +000037using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
38
Douglas Gregor0e8c4b92010-06-29 18:55:19 +000039namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}}
40namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
41
Douglas Gregorbb092ba2009-12-31 05:20:13 +000042bool test_string(std::string s) {
Douglas Gregorbfea2392009-12-31 08:11:17 +000043 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 McCall7c2342d2010-03-10 11:27:22 +000047 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 Gregorbb092ba2009-12-31 05:20:13 +000049}
Douglas Gregorfe0241e2009-12-31 09:10:24 +000050
51struct Base { };
John McCall7c2342d2010-03-10 11:27:22 +000052struct Derived : public Base { // expected-note{{base class 'Base' specified here}}
Douglas Gregor67dd1d42010-01-07 00:17:44 +000053 int member; // expected-note 3{{'member' declared here}}
Douglas Gregorfe0241e2009-12-31 09:10:24 +000054
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 Gregore3582012010-01-01 17:44:25 +000057
58 int getMember() const {
59 return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}}
60 }
61
62 int &getMember();
Douglas Gregorfe0241e2009-12-31 09:10:24 +000063};
Douglas Gregore3582012010-01-01 17:44:25 +000064
65int &Derived::getMember() {
66 return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}}
67}
Douglas Gregor3b887352011-04-27 04:48:22 +000068
69typedef int Integer; // expected-note{{'Integer' declared here}}
70int global_value; // expected-note{{'global_value' declared here}}
71
72int 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 Gregord8bba9c2011-06-28 16:20:02 +000077
78namespace nonstd {
79 typedef std::basic_string<char> yarn; // expected-note{{'nonstd::yarn' declared here}}
80}
81
82yarn str4; // expected-error{{unknown type name 'yarn'; did you mean 'nonstd::yarn'?}}
Douglas Gregor07f4a062011-07-01 21:27:45 +000083
84namespace check_bool {
85 void f() {
86 Bool b; // expected-error{{use of undeclared identifier 'Bool'; did you mean 'bool'?}}
87 }
88}