[cfe-dev] Incrementing typedefed pointer

Steve Naroff snaroff at apple.com
Sun Nov 11 06:17:05 PST 2007


I just tested/committed your patch.

Great job!

snaroff

On Nov 11, 2007, at 4:46 AM, Sanghyeon Seo wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list