From: Sebastian Redl Date: Wed, 22 Feb 2012 09:07:21 +0000 (+0000) Subject: Throw away stray CXXDefaultArgExprs. Fixes PR12061. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=428c620478d513081399798db5550bf0c779f244;p=clang Throw away stray CXXDefaultArgExprs. Fixes PR12061. 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 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index c8e640f191..30f143a825 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -1018,6 +1018,13 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, } else if (Initializer && isa(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(Initializer)) + Initializer = 0; assert((!Initializer || isa(Initializer) || isa(Initializer)) && "Initializer expression that cannot have been implicitly created."); diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index d355c7cc51..579ec33a43 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -460,3 +460,43 @@ namespace P12023 { return 0; } } + +namespace PR12061 { + template struct scoped_array { + scoped_array(C* p = __null); + }; + template struct Foo { + Foo() : a_(new scoped_array[5]) { } + scoped_array< scoped_array > a_; + }; + class Bar {}; + Foo x; + + template struct scoped_array2 { + scoped_array2(C* p = __null, C* q = __null); + }; + template struct Foo2 { + Foo2() : a_(new scoped_array2[5]) { } + scoped_array2< scoped_array2 > a_; + }; + class Bar2 {}; + Foo2 x2; + + class MessageLoop { + public: + explicit MessageLoop(int type = 0); + }; + template + class CookieStoreTest { + protected: + CookieStoreTest() { + new MessageLoop; + } + }; + struct CookieMonsterTestTraits { + }; + class DeferredCookieTaskTest : public CookieStoreTest + { + DeferredCookieTaskTest() {} + }; +}