]> granicus.if.org Git - clang/commitdiff
Congruent diagnostic for void* arithmetic.
authorAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 13 Sep 2010 06:50:07 +0000 (06:50 +0000)
committerAbramo Bagnara <abramo.bagnara@gmail.com>
Mon, 13 Sep 2010 06:50:07 +0000 (06:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113740 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/CodeGen/pointer-arithmetic.c
test/Sema/pointer-addition.c

index 1152da9bdc037647b4e3c4c524d3fe18251922e4..9a394aeeb9aebea513c4dae80ea636bb7c79e9ef 100644 (file)
@@ -2418,7 +2418,11 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc,
     return ExprError();
   }
 
-  if (!ResultType->isDependentType() &&
+  if (ResultType->isVoidType() && !getLangOptions().CPlusPlus) {
+    // GNU extension: subscripting on pointer to void
+    Diag(LLoc, diag::ext_gnu_void_ptr)
+      << BaseExpr->getSourceRange();
+  } else if (!ResultType->isDependentType() &&
       RequireCompleteType(LLoc, ResultType,
                           PDiag(diag::err_subscript_incomplete_type)
                             << BaseExpr->getSourceRange()))
index 33465e0aa137843f7d98ab8807adee5f739d8fac..f67a36d66e4b86bc3132f0086d35acb6902729d2 100644 (file)
@@ -9,6 +9,7 @@ int f1(const char *a, char *b) { return b - a; }
 // GNU extensions
 typedef void (*FP)(void);
 void *f2(void *a, int b) { return a + b; }
+void *f2_0(void *a, int b) { return &a[b]; }
 void *f2_1(void *a, int b) { return (a += b); }
 void *f3(int a, void *b) { return a + b; }
 void *f3_1(int a, void *b) { return (a += b); }
@@ -20,3 +21,5 @@ FP f6(int a, FP b) { return a + b; }
 FP f6_1(int a, FP b) { return (a += b); }
 FP f7(FP a, int b) { return a - b; }
 FP f7_1(FP a, int b) { return (a -= b); }
+void f8(void *a, int b) { return *(a + b); }
+void f8_1(void *a, int b) { return a[b]; }
index 34f8bbbfcd6d68947b8805c6a2e606b58f575913..aa425a7fd9d9810a0215a8ae926367d5ac659078 100644 (file)
@@ -9,6 +9,7 @@ void a(S* b, void* c) {
   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}}
   /* The next couple tests are only pedantic warnings in gcc */
   void (*d)(S*,void*) = a;