Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | bbe2743 | 2008-11-21 16:29:06 +0000 | [diff] [blame] | 2 | typedef int INT; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 3 | typedef INT REALLY_INT; // expected-note {{previous definition is here}} |
Douglas Gregor | bbe2743 | 2008-11-21 16:29:06 +0000 | [diff] [blame] | 4 | typedef REALLY_INT REALLY_REALLY_INT; |
| 5 | typedef REALLY_INT BOB; |
Chris Lattner | d0344a4 | 2009-02-19 23:45:49 +0000 | [diff] [blame] | 6 | typedef float REALLY_INT; // expected-error{{typedef redefinition with different types ('float' vs 'INT' (aka 'int'))}} |
Douglas Gregor | bbe2743 | 2008-11-21 16:29:06 +0000 | [diff] [blame] | 7 | |
Douglas Gregor | 6697312 | 2009-01-28 17:15:10 +0000 | [diff] [blame] | 8 | struct X { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 9 | typedef int result_type; // expected-note {{previous definition is here}} |
| 10 | typedef INT result_type; // expected-error {{redefinition of 'result_type'}} |
Douglas Gregor | bbe2743 | 2008-11-21 16:29:06 +0000 | [diff] [blame] | 11 | }; |
Douglas Gregor | 6697312 | 2009-01-28 17:15:10 +0000 | [diff] [blame] | 12 | |
| 13 | struct Y; // expected-note{{previous definition is here}} |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 14 | typedef int Y; // expected-error{{typedef redefinition with different types ('int' vs 'Y')}} |
Douglas Gregor | 6697312 | 2009-01-28 17:15:10 +0000 | [diff] [blame] | 15 | |
John McCall | 0d6b164 | 2010-04-23 18:46:30 +0000 | [diff] [blame] | 16 | typedef int Y2; // expected-note{{declared here}} |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 17 | struct Y2; // expected-error{{definition of type 'Y2' conflicts with typedef of the same name}} |
Douglas Gregor | 6697312 | 2009-01-28 17:15:10 +0000 | [diff] [blame] | 18 | |
| 19 | void f(); // expected-note{{previous definition is here}} |
| 20 | typedef int f; // expected-error{{redefinition of 'f' as different kind of symbol}} |
| 21 | |
| 22 | typedef int f2; // expected-note{{previous definition is here}} |
| 23 | void f2(); // expected-error{{redefinition of 'f2' as different kind of symbol}} |
| 24 | |
| 25 | typedef struct s s; |
| 26 | typedef int I; |
| 27 | typedef int I; |
| 28 | typedef I I; |
| 29 | |
| 30 | struct s { }; |
| 31 | |
John McCall | 5126fd0 | 2009-12-30 00:31:22 +0000 | [diff] [blame] | 32 | // PR5874 |
| 33 | namespace test1 { |
| 34 | typedef int foo; |
| 35 | namespace a { using test1::foo; }; |
| 36 | typedef int foo; |
| 37 | using namespace a; |
| 38 | foo x; |
| 39 | } |
Douglas Gregor | c8fd2da | 2010-04-27 16:26:47 +0000 | [diff] [blame] | 40 | |
| 41 | namespace PR6923 { |
| 42 | struct A; |
| 43 | |
| 44 | extern "C" { |
| 45 | struct A; |
| 46 | typedef struct A A; |
| 47 | } |
| 48 | |
| 49 | struct A; |
| 50 | } |
Douglas Gregor | aef0199 | 2010-07-13 06:37:01 +0000 | [diff] [blame] | 51 | |
| 52 | namespace PR7462 { |
| 53 | struct A {}; |
| 54 | typedef int operator! (A); // expected-error{{typedef name must be an identifier}} |
| 55 | int i = !A(); // expected-error{{invalid argument type}} |
| 56 | } |
Richard Smith | 874d253 | 2011-11-29 05:27:40 +0000 | [diff] [blame] | 57 | |
| 58 | template<typename T> |
| 59 | typedef T f(T t) { return t; } // expected-error {{function definition declared 'typedef'}} |
| 60 | int k = f(0); |
| 61 | int k2 = k; |
Rafael Espindola | 5df37bd | 2011-12-26 22:42:47 +0000 | [diff] [blame] | 62 | |
| 63 | namespace PR11630 { |
| 64 | template <class T> |
| 65 | struct S |
| 66 | { |
| 67 | static const unsigned C = 1; |
| 68 | static void f() |
| 69 | { |
| 70 | typedef int q[C == 1 ? 1 : -1]; // expected-note{{previous definition is here}} |
| 71 | typedef int q[C >= 1 ? 2 : -2]; // expected-error{{typedef redefinition with different types ('int [2]' vs 'int [1]')}} |
| 72 | typedef int n[C == 1 ? 1 : -1]; |
| 73 | typedef int n[C >= 1 ? 1 : -1]; |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | template <int T> |
| 78 | struct S2 |
| 79 | { |
| 80 | static void f() |
| 81 | { |
| 82 | typedef int q[1]; // expected-note{{previous definition is here}} |
| 83 | typedef int q[T]; // expected-error{{typedef redefinition with different types ('int [2]' vs 'int [1]')}} |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | void f() { |
| 88 | S<int> a; |
| 89 | a.f(); // expected-note{{in instantiation of member function 'PR11630::S<int>::f' requested here}} |
| 90 | S2<1> b; |
| 91 | b.f(); |
| 92 | S2<2> b2; |
| 93 | b2.f(); // expected-note{{in instantiation of member function 'PR11630::S2<2>::f' requested here}} |
| 94 | } |
| 95 | } |