[cfe-dev] Incrementing typedefed pointer

Sanghyeon Seo sanxiyn at gmail.com
Sun Nov 11 04:46:50 PST 2007


Hi, I'm new to the list. clang looks like a cool project.

I built llvm and cfe SVN trunk r43993.

Following C program:

#include <stdio.h>
typedef int *pint;
int main() {
    int a[5] = {0};
    pint p = a;
    p++;
    printf("%d\n", *p);
}

generates an error, which is incorrect.

test.c:6:6: error: cannot modify value of type 'pint'

I hardly know any C++, but I came up with the following patch anyway.
Please comment.

Index: Sema/SemaExpr.cpp
===================================================================
--- Sema/SemaExpr.cpp   (revision 43993)
+++ Sema/SemaExpr.cpp   (working copy)
@@ -1414,7 +1414,7 @@
   assert(!resType.isNull() && "no type for increment/decrement expression");

   // C99 6.5.2.4p1: We allow complex as a GCC extension.
-  if (const PointerType *pt = dyn_cast<PointerType>(resType)) {
+  if (const PointerType *pt = resType->getAsPointerType()) {
     if (!pt->getPointeeType()->isObjectType()) { // C99 6.5.2.4p2, 6.5.6p2
       Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type,
            resType.getAsString(), op->getSourceRange());

-- 
Seo Sanghyeon



More information about the cfe-dev mailing list