[cfe-commits] r51907 - in /cfe/trunk: lib/AST/Expr.cpp test/Sema/gcc-cast-ext.m

Eli Friedman eli.friedman at gmail.com
Tue Jun 3 10:43:47 PDT 2008


On Tue, Jun 3, 2008 at 10:15 AM, Steve Naroff <snaroff at apple.com> wrote:
==============================================================================
> --- cfe/trunk/lib/AST/Expr.cpp (original)
> +++ cfe/trunk/lib/AST/Expr.cpp Tue Jun  3 12:15:29 2008
> @@ -918,6 +918,11 @@
>     if (!SubExpr->getType()->isArithmeticType() ||
>         !getType()->isIntegerType()) {
>       if (Loc) *Loc = SubExpr->getLocStart();
> +      // GCC accepts pointers as an extension.
> +      // FIXME: check getLangOptions().NoExtensions. At the moment, it doesn't
> +      // appear possible to get langOptions() from the Expr.
> +      if (SubExpr->getType()->isPointerType()) // && !NoExtensions
> +        return true;
>       return false;
>     }

This is no good: this potentially breaks standards-compliant code (as
I said in reply to the mail you sent to cfe-dev), and it's completely
impossible to warn for illegal cases.  If you really need this
specific construct to work, we can add a special-case to the struct
decl code to allow it.

Also, your implementation is completely broken; it treats *all*
pointers as integer constant expressions, and it doesn't actually
bother to compute the correct value.  This will silently break code
that uses this construct; if I'm not mistaken, sizeof(struct xx) in
the testcase you added is zero.

-Eli



More information about the cfe-commits mailing list