A bug?

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!


--------------- 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.DiscardCleanupsInEvaluationContext();

   return ThisDecl;

This should probably be in ActOnInitializerError.

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;