typo.cpp 5.7 KB

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