summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-06-27 08:02:19 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-06-27 08:02:19 +0000
commitc93322182615e2333e85ff21d8a93b2e4fce1e3d (patch)
tree3628201f819d00bbce177993fb02fcc1b6f207ed /clang/test/Sema
parenta61df3f843f3ec49fb6952a5a4cf94c0938307a4 (diff)
downloadbcm5719-llvm-c93322182615e2333e85ff21d8a93b2e4fce1e3d.tar.gz
bcm5719-llvm-c93322182615e2333e85ff21d8a93b2e4fce1e3d.zip
Factor out (some of) the checking for invalid forms of pointer
arithmetic into a couple of common routines. Use these to make the messages more consistent in the various contexts, especially in terms of consistently diagnosing binary operators with invalid types on both the left- and right-hand side. Also, improve the grammar and wording of the messages some, handling both two pointers and two (different) types. The wording of function pointer arithmetic diagnostics still strikes me as poorly phrased, and I worry this makes them slightly more awkward if more consistent. I'm hoping to fix that with a follow-on patch and test case that will also make them more helpful when a typedef or template type parameter makes the type completely opaque. Suggestions on better wording are very welcome, thanks to Richard Smith for some initial help on that front. llvm-svn: 133906
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/incomplete-decl.c2
-rw-r--r--clang/test/Sema/pointer-addition.c26
-rw-r--r--clang/test/Sema/pointer-subtract-compat.c2
-rw-r--r--clang/test/Sema/typecheck-binop.c6
4 files changed, 18 insertions, 18 deletions
diff --git a/clang/test/Sema/incomplete-decl.c b/clang/test/Sema/incomplete-decl.c
index e5b6d5f0da6..0214a0c6ce4 100644
--- a/clang/test/Sema/incomplete-decl.c
+++ b/clang/test/Sema/incomplete-decl.c
@@ -22,7 +22,7 @@ void func() {
}
int h[]; // expected-warning {{tentative array definition assumed to have one element}}
-int (*i)[] = &h+1; // expected-error {{arithmetic on pointer to incomplete type 'int (*)[]'}}
+int (*i)[] = &h+1; // expected-error {{arithmetic on a pointer to an incomplete type 'int []'}}
struct bar j = {1}; // expected-error {{variable has incomplete type 'struct bar'}} \
expected-note {{forward declaration of 'struct bar'}}
diff --git a/clang/test/Sema/pointer-addition.c b/clang/test/Sema/pointer-addition.c
index 01047a06849..af8258a0f2e 100644
--- a/clang/test/Sema/pointer-addition.c
+++ b/clang/test/Sema/pointer-addition.c
@@ -3,19 +3,19 @@
typedef struct S S; // expected-note 3 {{forward declaration of 'struct S'}}
void a(S* b, void* c) {
void (*fp)(int) = 0;
- b++; // expected-error {{arithmetic on pointer to incomplete type}}
- b += 1; // expected-error {{arithmetic on pointer to incomplete type}}
- c++; // expected-warning {{use of GNU void* extension}}
- c += 1; // expected-warning {{use of GNU void* extension}}
- c--; // expected-warning {{use of GNU void* extension}}
- c -= 1; // expected-warning {{use of GNU void* extension}}
- (void) c[1]; // expected-warning {{use of GNU void* extension}}
- b = 1+b; // expected-error {{arithmetic on pointer to incomplete type}}
+ b++; // expected-error {{arithmetic on a pointer to an incomplete type}}
+ b += 1; // expected-error {{arithmetic on a pointer to an incomplete type}}
+ c++; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c += 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c--; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ c -= 1; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ (void) c[1]; // expected-warning {{arithmetic on a pointer to void is a GNU extension}}
+ b = 1+b; // expected-error {{arithmetic on a pointer to an incomplete type}}
/* The next couple tests are only pedantic warnings in gcc */
void (*d)(S*,void*) = a;
- d += 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
- d++; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
- d--; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
- d -= 1; // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
- (void)(1 + d); // expected-warning {{arithmetic on pointer to function type 'void (*)(S *, void *)' is a GNU extension}}
+ d += 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d++; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d--; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ d -= 1; // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
+ (void)(1 + d); // expected-warning {{arithmetic on a pointer to the function type 'void (S *, void *)' is a GNU extension}}
}
diff --git a/clang/test/Sema/pointer-subtract-compat.c b/clang/test/Sema/pointer-subtract-compat.c
index 70340c6a4cd..b801f81473b 100644
--- a/clang/test/Sema/pointer-subtract-compat.c
+++ b/clang/test/Sema/pointer-subtract-compat.c
@@ -7,5 +7,5 @@ int a(char* a, rchar* b) {
// <rdar://problem/6520707>
void f0(void (*fp)(void)) {
- int x = fp - fp; // expected-warning{{arithmetic on pointer to function type 'void (*)(void)' is a GNU extension}}
+ int x = fp - fp; // expected-warning{{arithmetic on pointers to the function type 'void (void)' is a GNU extension}}
}
diff --git a/clang/test/Sema/typecheck-binop.c b/clang/test/Sema/typecheck-binop.c
index 712dad279db..be52d0bd844 100644
--- a/clang/test/Sema/typecheck-binop.c
+++ b/clang/test/Sema/typecheck-binop.c
@@ -7,15 +7,15 @@ int sub1(int *a, double *b) {
}
void *sub2(struct incomplete *P) {
- return P-4; /* expected-error{{subtraction of pointer 'struct incomplete *' requires pointee to be a complete object type}} */
+ return P-4; /* expected-error{{arithmetic on a pointer to an incomplete type 'struct incomplete'}} */
}
void *sub3(void *P) {
- return P-4; /* expected-warning{{GNU void* extension}} */
+ return P-4; /* expected-warning{{arithmetic on a pointer to void is a GNU extension}} */
}
int sub4(void *P, void *Q) {
- return P-Q; /* expected-warning{{GNU void* extension}} */
+ return P-Q; /* expected-warning{{arithmetic on pointers to void is a GNU extension}} */
}
int sub5(void *P, int *Q) {
OpenPOWER on IntegriCloud