[cfe-dev] A bug?

Pan, Wei wei.pan at intel.com
Fri Jun 28 19:58:24 PDT 2013


ActOnInitializerError seems to be called if the initializer is ill-formed. I tweaked the example a bit, so that the initializer is good but AddInitializerToDecl will fail in the middle. That is why I tried to do the cleanup in the very end. 

struct A { ~A(); };
struct B {};

void foo() {
  B b = A();
  int c = 0;
}

-----Original Message-----
From: metafoo at gmail.com [mailto:metafoo at gmail.com] On Behalf Of Richard Smith
Sent: Friday, June 28, 2013 5:24 PM
To: Pan, Wei
Cc: clang-dev Developers
Subject: Re: [cfe-dev] A bug?

On Fri, Jun 28, 2013 at 8:54 AM, Pan, Wei <wei.pan at intel.com> wrote:
> With the following example,
>
> struct A { ~A(); };
>
> void foo() {
>   A a = 1 + A();  // bad initializer to a
>   int i = 0;
> }
>
> The AST for the second statement "int i = 0;" is
>
> `-DeclStmt 0x3f0cb60 <line:9:3, col:12>  `-VarDecl 0x3f0cad0 <col:3, 
> col:11> b 'int'
>   `-ExprWithCleanups 0x3f0cb48 <col:11> 'int'
>    `-IntegerLiteral 0x3f0cb28 <col:11> 'int' 1
>
> which looks bad to have an extra "ExprWithCleanups" node.
>
> Does the following simple change fix it properly? Thanks!
>
> Wei
>
> --------------- inlined patch -----------------
>
> diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 
> 451bf95..8f0c7ae 100644
> --- a/lib/Parse/ParseDecl.cpp
> +++ b/lib/Parse/ParseDecl.cpp
> @@ -1933,6 +1933,7 @@ Decl *Parser::ParseDeclarationAfterDeclaratorAndAttributes(Declarator &D,
>    }
>
>    Actions.FinalizeDeclaration(ThisDecl);
> +  Actions.DiscardCleanupsInEvaluationContext();

This should probably be in ActOnInitializerError.




More information about the cfe-dev mailing list