1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: cp %s %t
3// RUN: not %clang_cc1 -fsyntax-only -fixit -x c++ %t
4// RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t
5// RUN: grep test_string %t
6
7namespace std {
8  template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}} \
9                                            // expected-note {{'otherstd::basic_string' declared here}}
10  public:
11    int find(const char *substr); // expected-note{{'find' declared here}}
12    static const int npos = -1; // expected-note{{'npos' declared here}}
13  };
14
15  typedef basic_string<char> string; // expected-note 2{{'string' declared here}}
16}
17
18namespace otherstd { // expected-note 2{{'otherstd' declared here}} \
19                     // expected-note{{namespace 'otherstd' defined here}}
20  using namespace std;
21}
22
23using namespace std;
24
25other_std::strng str1; // expected-error{{use of undeclared identifier 'other_std'; did you mean 'otherstd'?}} \
26// expected-error{{no type named 'strng' in namespace 'otherstd'; did you mean 'string'?}}
27tring str2; // expected-error{{unknown type name 'tring'; did you mean 'string'?}}
28
29::other_std::string str3; // expected-error{{no member named 'other_std' in the global namespace; did you mean 'otherstd'?}}
30
31float area(float radius, // expected-note{{'radius' declared here}}
32           float pi) {
33  return radious * pi; // expected-error{{did you mean 'radius'?}}
34}
35
36using namespace othestd; // expected-error{{no namespace named 'othestd'; did you mean 'otherstd'?}}
37namespace blargh = otherstd; // expected-note 3{{namespace 'blargh' defined here}}
38using namespace ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
39
40namespace wibble = blarg; // expected-error{{no namespace named 'blarg'; did you mean 'blargh'?}}
41namespace wobble = ::blarg; // expected-error{{no namespace named 'blarg' in the global namespace; did you mean 'blargh'?}}
42
43bool test_string(std::string s) {
44  basc_string<char> b1; // expected-error{{no template named 'basc_string'; did you mean 'basic_string'?}}
45  std::basic_sting<char> b2; // expected-error{{no template named 'basic_sting' in namespace 'std'; did you mean 'basic_string'?}}
46  (void)b1;
47  (void)b2;
48  return s.fnd("hello") // expected-error{{no member named 'fnd' in 'std::basic_string<char>'; did you mean 'find'?}}
49    == std::string::pos; // expected-error{{no member named 'pos' in 'std::basic_string<char>'; did you mean 'npos'?}}
50}
51
52struct Base { };
53struct Derived : public Base { // expected-note{{base class 'Base' specified here}}
54  int member; // expected-note 3{{'member' declared here}}
55
56  Derived() : base(), // expected-error{{initializer 'base' does not name a non-static data member or base class; did you mean the base class 'Base'?}}
57              ember() { } // expected-error{{initializer 'ember' does not name a non-static data member or base class; did you mean the member 'member'?}}
58
59  int getMember() const {
60    return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}}
61  }
62
63  int &getMember();
64};
65
66int &Derived::getMember() {
67  return ember; // expected-error{{use of undeclared identifier 'ember'; did you mean 'member'?}}
68}
69
70typedef int Integer; // expected-note{{'Integer' declared here}}
71int global_value; // expected-note{{'global_value' declared here}}
72
73int foo() {
74  integer * i = 0; // expected-error{{unknown type name 'integer'; did you mean 'Integer'?}}
75  unsinged *ptr = 0; // expected-error{{use of undeclared identifier 'unsinged'; did you mean 'unsigned'?}}
76  return *i + *ptr + global_val; // expected-error{{use of undeclared identifier 'global_val'; did you mean 'global_value'?}}
77}
78
79namespace nonstd {
80  typedef std::basic_string<char> yarn; // expected-note 2 {{'nonstd::yarn' declared here}}
81  int narf; // expected-note{{'nonstd::narf' declared here}}
82}
83
84yarn str4; // expected-error{{unknown type name 'yarn'; did you mean 'nonstd::yarn'?}}
85wibble::yarn str5; // expected-error{{no type named 'yarn' in namespace 'otherstd'; did you mean 'nonstd::yarn'?}}
86
87int poit() {
88  nonstd::basic_string<char> str; // expected-error{{no template named 'basic_string' in namespace 'nonstd'; did you mean 'otherstd::basic_string'?}}
89  return wibble::narf; // expected-error{{no member named 'narf' in namespace 'otherstd'; did you mean 'nonstd::narf'?}}
90}
91
92namespace check_bool {
93  void f() {
94    Bool b; // expected-error{{use of undeclared identifier 'Bool'; did you mean 'bool'?}}
95  }
96}
97
98namespace outr {
99}
100namespace outer {
101  namespace inner { // expected-note{{'outer::inner' declared here}} \
102                    // expected-note{{namespace 'outer::inner' defined here}} \
103                    // expected-note{{'inner' declared here}}
104    int i;
105  }
106}
107
108using namespace outr::inner; // expected-error{{no namespace named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}}
109
110void func() {
111  outr::inner::i = 3; // expected-error{{no member named 'inner' in namespace 'outr'; did you mean 'outer::inner'?}}
112  outer::innr::i = 4; // expected-error{{no member named 'innr' in namespace 'outer'; did you mean 'inner'?}}
113}
114
115struct base {
116};
117struct derived : base {
118  int i;
119};
120
121void func2() {
122  derived d;
123  // FIXME: we should offer a fix here. We do if the 'i' is misspelled, but we don't do name qualification changes
124  //        to replace base::i with derived::i as we would for other qualified name misspellings.
125  // d.base::i = 3;
126}
127