"flexible array initialization is a GNU extension">, InGroup<GNUFlexibleArrayInitializer>;
// Declarations.
+def err_redeclaration_different_type : Error<
+ "redeclaration of %0 with a different type%diff{: $ vs $|}1,2">;
def err_bad_variable_name : Error<
"%0 cannot be the name of a variable or data member">;
def err_bad_parameter_name : Error<
//
// Neither C nor C++ requires a diagnostic for this, but we should still try
// to diagnose it.
- Diag(New->getLocation(), diag::err_redefinition_different_type)
- << New->getDeclName() << New->getType() << Old->getType();
- Diag(Old->getLocation(), diag::note_previous_definition);
+ Diag(New->getLocation(), New->isThisDeclarationADefinition()
+ ? diag::err_redefinition_different_type
+ : diag::err_redeclaration_different_type)
+ << New->getDeclName() << New->getType() << Old->getType();
+
+ diag::kind PrevDiag;
+ SourceLocation OldLocation;
+ std::tie(PrevDiag, OldLocation) =
+ getNoteDiagForInvalidRedeclaration(Old, New);
+ Diag(OldLocation, PrevDiag);
return New->setInvalidDecl();
}
}
template<typename T> void n() {
- extern T n_var; // expected-error {{redefinition of 'n_var' with a different type: 'double' vs 'int'}} expected-note {{previous}}
+ extern T n_var; // expected-error {{redeclaration of 'n_var' with a different type: 'double' vs 'int'}} expected-note {{previous}}
extern T n_fn(); // expected-error {{functions that differ only in their return type cannot be overloaded}} expected-note {{previous}}
}
template void n<int>();
extern int f3(float); // okay: considered distinct
extern float v0;
-// expected-error@-1{{redefinition of 'v0' with a different type: 'float' vs 'int'}}
-// expected-note@Inputs/linkage-merge-sub.h:6{{previous definition is here}}
+// expected-error@-1{{redeclaration of 'v0' with a different type: 'float' vs 'int'}}
+// expected-note@Inputs/linkage-merge-sub.h:6{{previous declaration is here}}
static float v1;
static float v2;
namespace diff_types {
#ifdef ERROR
- template<typename T> extern T err0; // expected-error {{redefinition of 'err0' with a different type: 'T' vs 'float'}} // expected-note@42 {{previous definition is here}}
- template<typename T> extern float err1; // expected-error {{redefinition of 'err1' with a different type: 'float' vs 'T'}} // expected-note@43 {{previous definition is here}}
+ template<typename T> extern T err0; // expected-error {{redeclaration of 'err0' with a different type: 'T' vs 'float'}} // expected-note@42 {{previous declaration is here}}
+ template<typename T> extern float err1; // expected-error {{redeclaration of 'err1' with a different type: 'float' vs 'T'}} // expected-note@43 {{previous declaration is here}}
#endif
template<typename T> extern T def;
}
extern int a1[];
int a1[1];
-extern int a2[]; // expected-note {{previous definition is here}}
+extern int a2[]; // expected-note {{previous declaration is here}}
float a2[1]; // expected-error {{redefinition of 'a2'}}
extern int a3[][2];
int a3[1][2];
-extern int a4[][2]; // expected-note {{previous definition is here}}
+extern int a4[][2]; // expected-note {{previous declaration is here}}
int a4[2]; // expected-error {{redefinition of 'a4'}}
-extern int a5[1][2][3]; // expected-note {{previous definition is here}}
+extern int a5[1][2][3]; // expected-note {{previous declaration is here}}
int a5[3][2][1]; // expected-error {{redefinition of 'a5'}}
__declspec(dllimport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
// Import in local scope.
-__declspec(dllimport) float LocalRedecl1; // expected-note{{previous definition is here}}
-__declspec(dllimport) float LocalRedecl2; // expected-note{{previous definition is here}}
-__declspec(dllimport) float LocalRedecl3; // expected-note{{previous definition is here}}
+__declspec(dllimport) float LocalRedecl1; // expected-note{{previous declaration is here}}
+__declspec(dllimport) float LocalRedecl2; // expected-note{{previous declaration is here}}
+__declspec(dllimport) float LocalRedecl3; // expected-note{{previous declaration is here}}
__declspec(dllimport) float LocalRedecl4;
void functionScope() {
- __declspec(dllimport) int LocalRedecl1; // expected-error{{redefinition of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
- int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redefinition of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
- int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redefinition of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
+ __declspec(dllimport) int LocalRedecl1; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
+ int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
+ int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
__declspec(dllimport) int LocalVarDecl;
__declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
void __attribute__((stdcall)) variadic(int a, ...);
#ifdef MRTD
-// expected-note@+3 {{previous definition is here}}
-// expected-error@+3 {{redefinition of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((stdcall))'}}
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((stdcall))'}}
#endif
extern void (*a)(int, int);
__attribute__((cdecl)) extern void (*a)(int, int);
__attribute__((cdecl)) extern void (*b)(int, ...);
#ifndef MRTD
-// expected-note@+3 {{previous definition is here}}
-// expected-error@+3 {{redefinition of 'c' with a different type: 'void ((*))(int, int) __attribute__((stdcall))' vs 'void (*)(int, int)'}}
+// expected-note@+3 {{previous declaration is here}}
+// expected-error@+3 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((stdcall))' vs 'void (*)(int, int)'}}
#endif
extern void (*c)(int, int);
__attribute__((stdcall)) extern void (*c)(int, int);
/* RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify
*/
-extern struct {int a;} x; // expected-note {{previous definition is here}}
-extern struct {int a;} x; // expected-error {{redefinition of 'x'}}
+extern struct {int a;} x; // expected-note {{previous declaration is here}}
+extern struct {int a;} x; // expected-error {{redeclaration of 'x'}}
struct x;
int a(struct x* b) {
int i[(short)1];
enum e { e_1 };
-extern int j[sizeof(enum e)]; // expected-note {{previous definition}}
+extern int j[sizeof(enum e)]; // expected-note {{previous declaration}}
int j[42]; // expected-error {{redefinition of 'j' with a different type: 'int [42]' vs 'int [4]'}}
// rdar://6880104
// RUN: %clang_cc1 -fsyntax-only -verify %s
int outer1; // expected-note{{previous definition is here}}
-extern int outer2; // expected-note{{previous definition is here}}
+extern int outer2; // expected-note{{previous declaration is here}}
int outer4;
int outer4; // expected-note{{previous definition is here}}
int outer5;
int outer7(float);
void outer_test() {
- extern float outer1; // expected-error{{redefinition of 'outer1' with a different type}}
- extern float outer2; // expected-error{{redefinition of 'outer2' with a different type}}
- extern float outer3; // expected-note{{previous definition is here}}
+ extern float outer1; // expected-error{{redeclaration of 'outer1' with a different type}}
+ extern float outer2; // expected-error{{redeclaration of 'outer2' with a different type}}
+ extern float outer3; // expected-note{{previous declaration is here}}
double outer4;
- extern int outer5; // expected-note{{previous definition is here}}
+ extern int outer5; // expected-note{{previous declaration is here}}
extern int outer6; // expected-error{{redefinition of 'outer6' as different kind of symbol}}
int outer7;
extern int outer8; // expected-note{{previous definition is here}}
extern int outer9;
{
- extern int outer9; // expected-note{{previous definition is here}}
+ extern int outer9; // expected-note{{previous declaration is here}}
}
}
int outer8(int); // expected-error{{redefinition of 'outer8' as different kind of symbol}}
float outer9; // expected-error{{redefinition of 'outer9' with a different type}}
-extern int outer13; // expected-note{{previous definition is here}}
+extern int outer13; // expected-note{{previous declaration is here}}
void outer_shadowing_test() {
extern int outer10;
- extern int outer11; // expected-note{{previous definition is here}}
- extern int outer12; // expected-note{{previous definition is here}}
+ extern int outer11; // expected-note{{previous declaration is here}}
+ extern int outer12; // expected-note{{previous declaration is here}}
{
float outer10;
float outer11;
float outer12;
{
extern int outer10; // okay
- extern float outer11; // expected-error{{redefinition of 'outer11' with a different type}}
+ extern float outer11; // expected-error{{redeclaration of 'outer11' with a different type}}
static double outer12;
{
- extern float outer12; // expected-error{{redefinition of 'outer12' with a different type}}
- extern float outer13; // expected-error{{redefinition of 'outer13' with a different type}}
+ extern float outer12; // expected-error{{redeclaration of 'outer12' with a different type}}
+ extern float outer13; // expected-error{{redeclaration of 'outer13' with a different type}}
}
}
}
}
extern int b[];
-void g20() { extern int b[3]; } // expected-note{{previous definition is here}}
-void g21() { extern int b[4]; } // expected-error{{redefinition of 'b' with a different type: 'int [4]' vs 'int [3]'}}
+void g20() { extern int b[3]; } // expected-note{{previous declaration is here}}
+void g21() { extern int b[4]; } // expected-error{{redeclaration of 'b' with a different type: 'int [4]' vs 'int [3]'}}
int d[1][]; // expected-error {{array has incomplete element type 'int []'}}
-extern const int e[2]; // expected-note {{previous definition is here}}
+extern const int e[2]; // expected-note {{previous declaration is here}}
int e[] = { 1 }; // expected-error {{redefinition of 'e' with a different type: 'int []' vs 'const int [2]'}}
void f() {
thread_local int x;
static thread_local int y;
- extern thread_local int z; // expected-error {{redefinition of 'z' with a different type}}
+ extern thread_local int z; // expected-error {{redeclaration of 'z' with a different type}}
}
template<typename T>
class D0a {
template<typename U> static U Data;
- template<typename U> static CONST U Data<U*> = U(10); // expected-note {{previous definition is here}}
+ template<typename U> static CONST U Data<U*> = U(10); // expected-note {{previous declaration is here}}
};
template<>
template<typename U> U D0a<float>::Data<U*> = U(100); // expected-error {{redefinition of 'Data'}}
template<typename T>
class D1 {
template<typename U> static U Data;
- template<typename U> static CONST U Data<U*> = U(10); // expected-note {{previous definition is here}}
+ template<typename U> static CONST U Data<U*> = U(10); // expected-note {{previous declaration is here}}
};
template<>
template<typename U> U D1<float>::Data = U(10);
namespace pvt_extern {
template<typename T> T v = T();
template<typename T> extern T v; // redeclaration is allowed \
- // expected-note {{previous definition is here}}
- template<typename T> extern int v; // expected-error {{redefinition of 'v' with a different type: 'int' vs 'T'}}
+ // expected-note {{previous declaration is here}}
+ template<typename T> extern int v; // expected-error {{redeclaration of 'v' with a different type: 'int' vs 'T'}}
#ifndef PRECXX11
template<typename T> extern auto v; // expected-error {{declaration of variable 'v' with type 'auto' requires an initializer}}
template<typename T> auto v2 = T(); // expected-note {{previous definition is here}}
template<typename T> T v2; // expected-error {{redefinition of 'v2'}}
template<typename T> auto v3 = T(); // expected-note {{previous definition is here}}
- template<typename T> extern T v3; // expected-error {{redefinition of 'v3' with a different type: 'T' vs 'auto'}}
+ template<typename T> extern T v3; // expected-error {{redeclaration of 'v3' with a different type: 'T' vs 'auto'}}
template<typename T> auto v4 = T();
template<typename T> extern auto v4; // expected-error {{declaration of variable 'v4' with type 'auto' requires an initializer}}
}
__declspec(dllimport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
// Import in local scope.
-__declspec(dllimport) float LocalRedecl1; // expected-note{{previous definition is here}}
-__declspec(dllimport) float LocalRedecl2; // expected-note{{previous definition is here}}
-__declspec(dllimport) float LocalRedecl3; // expected-note{{previous definition is here}}
+__declspec(dllimport) float LocalRedecl1; // expected-note{{previous declaration is here}}
+__declspec(dllimport) float LocalRedecl2; // expected-note{{previous declaration is here}}
+__declspec(dllimport) float LocalRedecl3; // expected-note{{previous declaration is here}}
void functionScope() {
- __declspec(dllimport) int LocalRedecl1; // expected-error{{redefinition of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
- int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redefinition of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
- int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redefinition of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
+ __declspec(dllimport) int LocalRedecl1; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
+ int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
+ int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
__declspec(dllimport) int LocalVarDecl;
__declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
namespace test3 {
extern "C" {
void test3_f() {
- extern int test3_b; // expected-note {{previous definition is here}}
+ extern int test3_b; // expected-note {{previous declaration is here}}
}
}
extern "C" {
extern __weak id WLoopGetMain(); // expected-note {{previous declaration is here}}
extern id WLoopGetMain(); // expected-error {{conflicting types for 'WLoopGetMain'}}
-extern id p3; // expected-note {{previous definition is here}}
-extern __weak id p3; // expected-error {{redefinition of 'p3' with a different type}}
+extern id p3; // expected-note {{previous declaration is here}}
+extern __weak id p3; // expected-error {{redeclaration of 'p3' with a different type}}
-extern void *p4; // expected-note {{previous definition is here}}
-extern void * __strong p4; // expected-error {{redefinition of 'p4' with a different type}}
+extern void *p4; // expected-note {{previous declaration is here}}
+extern void * __strong p4; // expected-error {{redeclaration of 'p4' with a different type}}
extern id p5;
extern __strong id p5;
-extern char* __strong p6; // expected-note {{previous definition is here}}
-extern char* p6; // expected-error {{redefinition of 'p6' with a different type}}
+extern char* __strong p6; // expected-note {{previous declaration is here}}
+extern char* p6; // expected-error {{redeclaration of 'p6' with a different type}}
-extern __strong char* p7; // expected-note {{previous definition is here}}
-extern char* p7; // expected-error {{redefinition of 'p7' with a different type}}
+extern __strong char* p7; // expected-note {{previous declaration is here}}
+extern char* p7; // expected-error {{redeclaration of 'p7' with a different type}}
extern __weak id WLoopGetMain(); // expected-note {{previous declaration is here}}
extern id WLoopGetMain(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
-extern id p3; // expected-note {{previous definition is here}}
-extern __weak id p3; // expected-error {{redefinition of 'p3' with a different type}}
+extern id p3; // expected-note {{previous declaration is here}}
+extern __weak id p3; // expected-error {{redeclaration of 'p3' with a different type}}
-extern void *p4; // expected-note {{previous definition is here}}
-extern void * __strong p4; // expected-error {{redefinition of 'p4' with a different type}}
+extern void *p4; // expected-note {{previous declaration is here}}
+extern void * __strong p4; // expected-error {{redeclaration of 'p4' with a different type}}
extern id p5;
extern __strong id p5;
-extern char* __strong p6; // expected-note {{previous definition is here}}
-extern char* p6; // expected-error {{redefinition of 'p6' with a different type}}
+extern char* __strong p6; // expected-note {{previous declaration is here}}
+extern char* p6; // expected-error {{redeclaration of 'p6' with a different type}}
-extern __strong char* p7; // expected-note {{previous definition is here}}
-extern char* p7; // expected-error {{redefinition of 'p7' with a different type}}
+extern __strong char* p7; // expected-note {{previous declaration is here}}
+extern char* p7; // expected-error {{redeclaration of 'p7' with a different type}}