Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 2 | |
| 3 | // PR3990 |
| 4 | namespace N { |
| 5 | struct Wibble { |
| 6 | }; |
| 7 | |
| 8 | typedef Wibble foo; |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 9 | |
| 10 | int zeppelin; // expected-note{{declared here}} |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 11 | } |
| 12 | using namespace N; |
| 13 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 14 | foo::bar x; // expected-error{{no type named 'bar' in 'N::Wibble'}} |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 15 | |
| 16 | void f() { |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 17 | foo::bar = 4; // expected-error{{no member named 'bar' in 'N::Wibble'}} |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 18 | } |
| 19 | |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 20 | int f(foo::bar); // expected-error{{no type named 'bar' in 'N::Wibble'}} |
| 21 | |
| 22 | int f(doulbe); // expected-error{{did you mean 'double'?}} |
| 23 | |
| 24 | int fun(zapotron); // expected-error{{unknown type name 'zapotron'}} |
| 25 | int var(zepelin); // expected-error{{did you mean 'zeppelin'?}} |
| 26 | |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 27 | template<typename T> |
| 28 | struct A { |
| 29 | typedef T type; |
| 30 | |
| 31 | type f(); |
Richard Smith | 8f0a7e7 | 2012-05-15 21:29:55 +0000 | [diff] [blame] | 32 | |
| 33 | type g(); |
Richard Smith | 25582fc | 2012-05-16 23:40:17 +0000 | [diff] [blame] | 34 | |
| 35 | static int n; |
| 36 | static type m; |
| 37 | static int h(T::type, int); // expected-error{{missing 'typename'}} |
| 38 | static int h(T::type x, char); // expected-error{{missing 'typename'}} |
Douglas Gregor | a786fdb | 2009-10-13 23:27:22 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | template<typename T> |
| 42 | A<T>::type g(T t) { return t; } // expected-error{{missing 'typename'}} |
| 43 | |
| 44 | template<typename T> |
| 45 | A<T>::type A<T>::f() { return type(); } // expected-error{{missing 'typename'}} |
Richard Smith | 8f0a7e7 | 2012-05-15 21:29:55 +0000 | [diff] [blame] | 46 | |
| 47 | template<typename T> |
Richard Smith | 25582fc | 2012-05-16 23:40:17 +0000 | [diff] [blame] | 48 | void f(T::type) { } // expected-error{{missing 'typename'}} |
| 49 | |
| 50 | template<typename T> |
| 51 | void g(T::type x) { } // expected-error{{missing 'typename'}} |
| 52 | |
| 53 | template<typename T> |
| 54 | void f(T::type, int) { } // expected-error{{missing 'typename'}} |
| 55 | |
| 56 | template<typename T> |
| 57 | void f(T::type x, char) { } // expected-error{{missing 'typename'}} |
| 58 | |
| 59 | template<typename T> |
Richard Smith | 8f0a7e7 | 2012-05-15 21:29:55 +0000 | [diff] [blame] | 60 | void f(int, T::type) { } // expected-error{{missing 'typename'}} |
| 61 | |
| 62 | template<typename T> |
Richard Smith | 25582fc | 2012-05-16 23:40:17 +0000 | [diff] [blame] | 63 | void f(char, T::type x) { } // expected-error{{missing 'typename'}} |
| 64 | |
| 65 | template<typename T> |
Richard Smith | 8f0a7e7 | 2012-05-15 21:29:55 +0000 | [diff] [blame] | 66 | void f(int, T::type, int) { } // expected-error{{missing 'typename'}} |
| 67 | |
Richard Smith | 25582fc | 2012-05-16 23:40:17 +0000 | [diff] [blame] | 68 | template<typename T> |
| 69 | void f(int, T::type x, char) { } // expected-error{{missing 'typename'}} |
| 70 | |
Richard Smith | 0576681 | 2012-08-18 00:55:03 +0000 | [diff] [blame] | 71 | int *p; |
| 72 | |
| 73 | // FIXME: We should assume that 'undeclared' is a type, not a parameter name |
| 74 | // here, and produce an 'unknown type name' diagnostic instead. |
| 75 | int f1(undeclared, int); // expected-error{{requires a type specifier}} |
| 76 | |
| 77 | int f2(undeclared, 0); // expected-error{{undeclared identifier}} |
| 78 | |
| 79 | int f3(undeclared *p, int); // expected-error{{unknown type name 'undeclared'}} |
| 80 | |
| 81 | int f4(undeclared *p, 0); // expected-error{{undeclared identifier}} |
| 82 | |
| 83 | int *test(UnknownType *fool) { return 0; } // expected-error{{unknown type name 'UnknownType'}} |
| 84 | |
Richard Smith | 25582fc | 2012-05-16 23:40:17 +0000 | [diff] [blame] | 85 | template<typename T> int A<T>::n(T::value); // ok |
| 86 | template<typename T> |
| 87 | A<T>::type // expected-error{{missing 'typename'}} |
| 88 | A<T>::m(T::value, 0); // ok |
| 89 | |
| 90 | template<typename T> int A<T>::h(T::type, int) {} // expected-error{{missing 'typename'}} |
| 91 | template<typename T> int A<T>::h(T::type x, char) {} // expected-error{{missing 'typename'}} |
| 92 | |
| 93 | template<typename T> int h(T::type, int); // expected-error{{missing 'typename'}} |
| 94 | template<typename T> int h(T::type x, char); // expected-error{{missing 'typename'}} |
| 95 | |
| 96 | template<typename T> int junk1(T::junk); // expected-error{{declared as a template}} |
| 97 | template<typename T> int junk2(T::junk) throw(); // expected-error{{missing 'typename'}} |
| 98 | template<typename T> int junk3(T::junk) = delete; // expected-error{{missing 'typename'}} expected-warning{{C++11}} |
| 99 | template<typename T> int junk4(T::junk j); // expected-error{{missing 'typename'}} |
| 100 | |
| 101 | // FIXME: We can tell this was intended to be a function because it does not |
| 102 | // have a dependent nested name specifier. |
| 103 | template<typename T> int i(T::type, int()); // expected-error{{variable 'i' declared as a template}} |
| 104 | |
Richard Smith | 8f0a7e7 | 2012-05-15 21:29:55 +0000 | [diff] [blame] | 105 | // FIXME: We know which type specifier should have been specified here. Provide |
| 106 | // a fix-it to add 'typename A<T>::type' |
| 107 | template<typename T> |
| 108 | A<T>::g() { } // expected-error{{requires a type specifier}} |