]> granicus.if.org Git - clang/commitdiff
Throw away stray CXXDefaultArgExprs. Fixes PR12061.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Wed, 22 Feb 2012 09:07:21 +0000 (09:07 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Wed, 22 Feb 2012 09:07:21 +0000 (09:07 +0000)
I think there's a deeper problem here in the way TransformCXXConstructExpr works, but I won't tackle it now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151146 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaCXX/new-delete.cpp

index c8e640f1917733dce72716b596cc582dcf4e3f82..30f143a825b604e3429b5bdf3a62acb6910308d1 100644 (file)
@@ -1018,6 +1018,13 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
   } else if (Initializer && isa<InitListExpr>(Initializer))
     initStyle = CXXNewExpr::ListInit;
   else {
+    // In template instantiation, the initializer could be a CXXDefaultArgExpr
+    // unwrapped from a CXXConstructExpr that was implicitly built. There is no
+    // particularly sane way we can handle this (especially since it can even
+    // occur for array new), so we throw the initializer away and have it be
+    // rebuilt.
+    if (Initializer && isa<CXXDefaultArgExpr>(Initializer))
+      Initializer = 0;
     assert((!Initializer || isa<ImplicitValueInitExpr>(Initializer) ||
             isa<CXXConstructExpr>(Initializer)) &&
            "Initializer expression that cannot have been implicitly created.");
index d355c7cc51a91b71f91ce0599099a5afd17963a0..579ec33a43e8898454fb2d29e3a3b81d76b40209 100644 (file)
@@ -460,3 +460,43 @@ namespace P12023 {
       return 0;
   }
 }
+
+namespace PR12061 {
+  template <class C> struct scoped_array {
+    scoped_array(C* p = __null);
+  };
+  template <class Payload> struct Foo {
+    Foo() : a_(new scoped_array<int>[5]) { }
+    scoped_array< scoped_array<int> > a_;
+  };
+  class Bar {};
+  Foo<Bar> x;
+
+  template <class C> struct scoped_array2 {
+    scoped_array2(C* p = __null, C* q = __null);
+  };
+  template <class Payload> struct Foo2 {
+    Foo2() : a_(new scoped_array2<int>[5]) { }
+    scoped_array2< scoped_array2<int> > a_;
+  };
+  class Bar2 {};
+  Foo2<Bar2> x2;
+
+  class MessageLoop {
+  public:
+    explicit MessageLoop(int type = 0);
+  };
+  template <class CookieStoreTestTraits>
+  class CookieStoreTest {
+  protected:
+    CookieStoreTest() {
+      new MessageLoop;
+    }
+  };
+  struct CookieMonsterTestTraits {
+  };
+  class DeferredCookieTaskTest : public CookieStoreTest<CookieMonsterTestTraits>
+  {
+    DeferredCookieTaskTest() {}
+  };
+}