[cfe-dev] A bug?

Pan, Wei wei.pan at intel.com
Fri Jun 28 08:54:55 PDT 2013


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();
 
   return ThisDecl;
 }





More information about the cfe-dev mailing list