From: Douglas Gregor Date: Fri, 9 Apr 2010 17:53:29 +0000 (+0000) Subject: Improve diagnostics like "initializing from an expression of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08a41901e18aeb91b87d031b93df70374af02564;p=clang Improve diagnostics like "initializing from an expression of type..." with "initializing with an expression of type...", which reads better. Thanks to John for the improved wording. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100873 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 27632f171f..62769decf4 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2233,38 +2233,38 @@ def err_typecheck_convert_incompatible : Error< " %0 " "%select{from incompatible type|to parameter of incompatible type|" "from a function with incompatible result type|to incompatible type|" - "from an expression of incompatible type|to parameter of incompatible type|" + "with an expression of incompatible type|to parameter of incompatible type|" "to incompatible type}2 %1">; def warn_incompatible_qualified_id : Warning< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from incompatible type|to parameter of incompatible type|" "from a function with incompatible result type|to incompatible type|" - "from an expression of incompatible type|to parameter of incompatible type|" + "with an expression of incompatible type|to parameter of incompatible type|" "to incompatible type}2 %1">; def ext_typecheck_convert_pointer_int : ExtWarn< "incompatible pointer to integer conversion " "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">; + "with an expression of type|to parameter of type|to type}2 %1">; def ext_typecheck_convert_int_pointer : ExtWarn< "incompatible integer to pointer conversion " "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">; + "with an expression of type|to parameter of type|to type}2 %1">; def ext_typecheck_convert_pointer_void_func : Extension< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1 " + "with an expression of type|to parameter of type|to type}2 %1 " "converts between void pointer and function pointer">; def ext_typecheck_convert_incompatible_pointer_sign : ExtWarn< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1 " + "with an expression of type|to parameter of type|to type}2 %1 " "converts between pointers to integer types with different sign">, InGroup>; def ext_typecheck_convert_incompatible_pointer : ExtWarn< @@ -2272,38 +2272,38 @@ def ext_typecheck_convert_incompatible_pointer : ExtWarn< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">; + "with an expression of type|to parameter of type|to type}2 %1">; def ext_typecheck_convert_discards_qualifiers : ExtWarn< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1 discards " + "with an expression of type|to parameter of type|to type}2 %1 discards " "qualifiers">; def ext_nested_pointer_qualifier_mismatch : ExtWarn< "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1 discards " + "with an expression of type|to parameter of type|to type}2 %1 discards " "qualifiers in nested pointer types">; def warn_incompatible_vectors : Warning< "incompatible vector types " "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">, + "with an expression of type|to parameter of type|to type}2 %1">, InGroup, DefaultIgnore; def err_int_to_block_pointer : Error< "invalid block pointer conversion " "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">; + "with an expression of type|to parameter of type|to type}2 %1">; def err_typecheck_convert_incompatible_block_pointer : Error< "incompatible block pointer types " "%select{assigning to|passing|returning|converting|initializing|sending|casting}2" " %0 " "%select{from|to parameter of type|from a function with result type|to type|" - "from an expression of type|to parameter of type|to type}2 %1">; + "with an expression of type|to parameter of type|to type}2 %1">; def err_typecheck_convert_ambiguous : Error< "ambiguity in initializing value of type %0 with initializer of type %1">; diff --git a/test/FixIt/fixit-objc.m b/test/FixIt/fixit-objc.m index 072d50a69b..6aa1b33ea1 100644 --- a/test/FixIt/fixit-objc.m +++ b/test/FixIt/fixit-objc.m @@ -27,7 +27,7 @@ void h(id a); void f(Test *t) { NSString *a = "Foo"; id b = "Foo"; - A* c = "Foo"; // expected-warning {{incompatible pointer types initializing 'A *' from an expression of type 'char [4]'}} + A* c = "Foo"; // expected-warning {{incompatible pointer types initializing 'A *' with an expression of type 'char [4]'}} g("Foo"); h("Foo"); h(("Foo")); diff --git a/test/PCH/types.c b/test/PCH/types.c index 5ca6a6893f..c21b33a4ee 100644 --- a/test/PCH/types.c +++ b/test/PCH/types.c @@ -66,7 +66,7 @@ int_ptr_ptr ipp = &int_value_ptr; // TYPE_TYPEOF_EXPR typeof_17 *t17 = &int_value; struct S { int x, y; }; -typeof_17 t17_2 = (struct S){1, 2}; // expected-error{{initializing 'typeof_17' (aka 'int') from an expression of incompatible type 'struct S'}} +typeof_17 t17_2 = (struct S){1, 2}; // expected-error{{initializing 'typeof_17' (aka 'int') with an expression of incompatible type 'struct S'}} // TYPE_TYPEOF int_ptr_ptr2 ipp2 = &int_value_ptr; diff --git a/test/Sema/anonymous-struct-union.c b/test/Sema/anonymous-struct-union.c index b91426ca6c..d9e08397f2 100644 --- a/test/Sema/anonymous-struct-union.c +++ b/test/Sema/anonymous-struct-union.c @@ -101,4 +101,4 @@ struct s2 { typedef struct { int x; } a_struct; -int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' from an expression of incompatible type 'a_struct'}} +int tmp = (a_struct) { .x = 0 }; // expected-error {{initializing 'int' with an expression of incompatible type 'a_struct'}} diff --git a/test/Sema/array-init.c b/test/Sema/array-init.c index ac45ff77c8..f93b0878fd 100644 --- a/test/Sema/array-init.c +++ b/test/Sema/array-init.c @@ -9,7 +9,7 @@ int ary2[] = { x, y, z }; // expected-error{{initializer element is not a compil extern int fileScopeExtern[3] = { 1, 3, 5 }; // expected-warning{{'extern' variable has an initializer}} -static long ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' from an expression of type 'char [4]'}} +static long ary3[] = { 1, "abc", 3, 4 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}} void func() { int x = 1; @@ -44,11 +44,11 @@ void func() { int a,b,c; } z = { 1 }; - struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'struct threeElements *' from an expression of type 'int'}} + struct threeElements *p = 7; // expected-warning{{incompatible integer to pointer conversion initializing 'struct threeElements *' with an expression of type 'int'}} extern int blockScopeExtern[3] = { 1, 3, 5 }; // expected-error{{'extern' variable cannot have an initializer}} - static long x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' from an expression of type 'char [4]'}} + static long x2[3] = { 1.0, "abc" , 5.8 }; // expected-warning{{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [4]'}} } void test() { @@ -155,10 +155,10 @@ void charArrays() { char c[] = { "Hello" }; int l[sizeof(c) == 6 ? 1 : -1]; - int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'int' from an expression of type 'char [7]'}} + int i[] = { "Hello "}; // expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [7]'}} char c2[] = { "Hello", "Good bye" }; //expected-warning{{excess elements in char array initializer}} - int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'int' from an expression of type 'char [6]'}} + int i2[1] = { "Hello" }; //expected-warning{{incompatible pointer to integer conversion initializing 'int' with an expression of type 'char [6]'}} char c3[5] = { "Hello" }; char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}} @@ -191,12 +191,12 @@ void autoStructTest() { struct s1 {char a; char b;} t1; struct s2 {struct s1 c;} t2 = { t1 }; // The following is a less than great diagnostic (though it's on par with EDG). -struct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char' from an expression of type 'char [4]'}} +struct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [4]'}} int t4[sizeof t3 == 6 ? 1 : -1]; } struct foo { int z; } w; int bar (void) { - struct foo z = { w }; //expected-error{{initializing 'int' from an expression of incompatible type 'struct foo'}} + struct foo z = { w }; //expected-error{{initializing 'int' with an expression of incompatible type 'struct foo'}} return z.z; } struct s3 {void (*a)(void);} t5 = {autoStructTest}; diff --git a/test/Sema/block-call.c b/test/Sema/block-call.c index 01906bc4f2..318bc6b2a3 100644 --- a/test/Sema/block-call.c +++ b/test/Sema/block-call.c @@ -13,7 +13,7 @@ int main() { int (^IFP) () = PFR; // OK - const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' from an expression of type 'int (^)()'}} + const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int const (^)()' with an expression of type 'int (^)()'}} const int (^CICC) () = CIC; @@ -21,7 +21,7 @@ int main() { int * const (^IPCC1) () = IPCC; - int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' from an expression of type 'int *const (^)()'}} + int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *(^)()' with an expression of type 'int *const (^)()'}} int (^IPCC3) (const int) = PFR; @@ -29,14 +29,14 @@ int main() { int (^IPCC5) (int, char (^CArg) (double)) = IPCC4; - int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(float))' from an expression of type 'int (^)(int, char (^)(double))'}} + int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(float))' with an expression of type 'int (^)(int, char (^)(double))'}} IPCC2 = 0; IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning to 'int *(^)()' from 'int'}} int (^x)() = 0; - int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' from an expression of type 'int'}} + int (^y)() = 3; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}} int a = 1; - int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' from an expression of type 'int'}} + int (^z)() = a+4; // expected-error {{invalid block pointer conversion initializing 'int (^)()' with an expression of type 'int'}} } int blah() { diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c index f4eff65ed4..10b3b8480c 100644 --- a/test/Sema/block-return.c +++ b/test/Sema/block-return.c @@ -4,7 +4,7 @@ typedef void (^CL)(void); CL foo() { short y; - short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'short (^)(void)' from an expression of type 'int (^)(void)'}} + short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'short (^)(void)' with an expression of type 'int (^)(void)'}} CL X = ^{ if (2) @@ -26,7 +26,7 @@ CL foo() { return (char*)0; }; - double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'double (^)(void)' from an expression of type 'float (^)(void)'}} + double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'double (^)(void)' with an expression of type 'float (^)(void)'}} if (1) return (float)1.0; else @@ -78,8 +78,8 @@ static int funk(char *s) { } void next(); void foo4() { - int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(char const *)' from an expression of type 'int (^)(char *)'}} - int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(char const *)' from an expression of type 'int (char *)'}} + int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(char const *)' with an expression of type 'int (^)(char *)'}} + int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (*)(char const *)' with an expression of type 'int (char *)'}} int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \ // expected-note{{please include the header or explicitly provide a declaration for 'printf'}} @@ -109,7 +109,7 @@ void foo6() { void foo7() { - const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' from an expression of type 'int (^)(void)'}} + const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'int const (^)(void)' with an expression of type 'int (^)(void)'}} const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // OK int i; diff --git a/test/Sema/cast-to-union.c b/test/Sema/cast-to-union.c index a3683de10e..6f275e8b50 100644 --- a/test/Sema/cast-to-union.c +++ b/test/Sema/cast-to-union.c @@ -10,7 +10,7 @@ void test(int x) { union u w = (union u)2; // expected-warning {{C99 forbids casts to union type}} union u ww = (union u)1.0; // expected-error{{cast to union type from type 'double' not present in union}} -union u x = 7; // expected-error{{initializing 'union u' from an expression of incompatible type 'int'}} +union u x = 7; // expected-error{{initializing 'union u' with an expression of incompatible type 'int'}} int i; union u zz = (union u)i; // expected-error{{initializer element is not a compile-time constant}} expected-warning {{C99 forbids casts to union type}} diff --git a/test/Sema/compound-literal.c b/test/Sema/compound-literal.c index 205fa719b5..08c30b3c87 100644 --- a/test/Sema/compound-literal.c +++ b/test/Sema/compound-literal.c @@ -9,7 +9,7 @@ static int *p = (int []){2,4}; static int x = (int){1}; static int *p2 = (int []){2,x}; // -expected-error {{initializer element is not a compile-time constant}} -static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' from an expression of type 'char [2]'}} +static long *p3 = (long []){2,"x"}; // -expected-warning {{incompatible pointer to integer conversion initializing 'long' with an expression of type 'char [2]'}} typedef struct { } cache_t; // -expected-warning{{use of empty struct extension}} static cache_t clo_I1_cache = ((cache_t) { } ); // -expected-warning{{use of GNU empty initializer extension}} diff --git a/test/Sema/enum.c b/test/Sema/enum.c index caab5d3756..ba4e56b907 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -91,7 +91,7 @@ static enum e1 badfunc(struct s1 *q) { typedef enum { an_enumerator = 20 } an_enum; -char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' from an expression of type 'an_enum'}} +char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}} // PR4515 enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2}; diff --git a/test/Sema/invalid-init-diag.c b/test/Sema/invalid-init-diag.c index 1ade42f31c..3e4870e0ca 100644 --- a/test/Sema/invalid-init-diag.c +++ b/test/Sema/invalid-init-diag.c @@ -1,4 +1,4 @@ // RUN: %clang_cc1 %s -verify -fsyntax-only int a; -struct {int x;} x = a; // expected-error {{from an expression of incompatible type 'int'}} +struct {int x;} x = a; // expected-error {{with an expression of incompatible type 'int'}} diff --git a/test/Sema/predef.c b/test/Sema/predef.c index ace608e0e6..08a4a2bf83 100644 --- a/test/Sema/predef.c +++ b/test/Sema/predef.c @@ -6,7 +6,7 @@ void abcdefghi12(void) { } char *X = __func__; // expected-warning {{predefined identifier is only valid}} \ - expected-warning {{initializing 'char *' from an expression of type 'char const [1]' discards qualifiers}} + expected-warning {{initializing 'char *' with an expression of type 'char const [1]' discards qualifiers}} void a() { __func__[0] = 'a'; // expected-error {{variable is not assignable}} diff --git a/test/Sema/struct-compat.c b/test/Sema/struct-compat.c index ce63956c95..65bef9f605 100644 --- a/test/Sema/struct-compat.c +++ b/test/Sema/struct-compat.c @@ -13,5 +13,5 @@ struct x {int a;} *c = b; // expected-warning {{incompatible pointer types}} struct x {int a;} r; int b() { -struct x {char x;} s = r; // expected-error {{initializing 'struct x' from an expression of incompatible type 'struct x'}} +struct x {char x;} s = r; // expected-error {{initializing 'struct x' with an expression of incompatible type 'struct x'}} } diff --git a/test/Sema/warn-write-strings.c b/test/Sema/warn-write-strings.c index c0b7741125..04af00ca2d 100644 --- a/test/Sema/warn-write-strings.c +++ b/test/Sema/warn-write-strings.c @@ -1,4 +1,4 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s // PR4804 -char* x = "foo"; // expected-warning {{initializing 'char *' from an expression of type 'char const [4]' discards qualifiers}} +char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}} diff --git a/test/SemaObjC/comptypes-6.m b/test/SemaObjC/comptypes-6.m index cabf813679..98cf488792 100644 --- a/test/SemaObjC/comptypes-6.m +++ b/test/SemaObjC/comptypes-6.m @@ -9,7 +9,7 @@ extern Object* foo(void); static Derived *test(void) { - Derived *m = foo(); // expected-warning {{incompatible pointer types initializing 'Derived *' from an expression of type 'Object *'}} + Derived *m = foo(); // expected-warning {{incompatible pointer types initializing 'Derived *' with an expression of type 'Object *'}} return m; } diff --git a/test/SemaObjC/conditional-expr-3.m b/test/SemaObjC/conditional-expr-3.m index 9f34ca0e69..3b5f609e42 100644 --- a/test/SemaObjC/conditional-expr-3.m +++ b/test/SemaObjC/conditional-expr-3.m @@ -27,11 +27,11 @@ void f1(id x, A *a) { } void f2(id x) { - id l = x; // expected-warning {{initializing 'id' from an expression of incompatible type 'id'}} + id l = x; // expected-warning {{initializing 'id' with an expression of incompatible type 'id'}} } void f3(A *a) { - id l = a; // expected-warning {{ initializing 'id' from an expression of incompatible type 'A *'}} + id l = a; // expected-warning {{ initializing 'id' with an expression of incompatible type 'A *'}} } void f4(int cond, id x, A *a) { diff --git a/test/SemaObjC/conditional-expr-4.m b/test/SemaObjC/conditional-expr-4.m index 944c1753dd..b3317f5806 100644 --- a/test/SemaObjC/conditional-expr-4.m +++ b/test/SemaObjC/conditional-expr-4.m @@ -26,7 +26,7 @@ A *f1_a(int cond, A *a) { } void *f1_const_a(int x, void *p, const A * q) { - void *r = x ? p : q; // expected-warning{{initializing 'void *' from an expression of type 'void const *' discards qualifiers}} + void *r = x ? p : q; // expected-warning{{initializing 'void *' with an expression of type 'void const *' discards qualifiers}} return r; } diff --git a/test/SemaObjC/message.m b/test/SemaObjC/message.m index fc4bfcc95c..fed3961ce1 100644 --- a/test/SemaObjC/message.m +++ b/test/SemaObjC/message.m @@ -87,7 +87,7 @@ struct S { int X; } S; int test5(int X) { int a = [X somemsg]; // expected-warning {{receiver type 'int' is not 'id'}} \ expected-warning {{method '-somemsg' not found}} \ - expected-warning {{incompatible pointer to integer conversion initializing 'int' from an expression of type 'id'}} + expected-warning {{incompatible pointer to integer conversion initializing 'int' with an expression of type 'id'}} int b = [S somemsg]; // expected-error {{bad receiver type 'struct S'}} } diff --git a/test/SemaObjC/warn-write-strings.m b/test/SemaObjC/warn-write-strings.m index c0b7741125..04af00ca2d 100644 --- a/test/SemaObjC/warn-write-strings.m +++ b/test/SemaObjC/warn-write-strings.m @@ -1,4 +1,4 @@ // RUN: %clang_cc1 -verify -fsyntax-only -Wwrite-strings %s // PR4804 -char* x = "foo"; // expected-warning {{initializing 'char *' from an expression of type 'char const [4]' discards qualifiers}} +char* x = "foo"; // expected-warning {{initializing 'char *' with an expression of type 'char const [4]' discards qualifiers}}