From 124ae5399e558e14de172da727bd75c1372750b4 Mon Sep 17 00:00:00 2001 From: Richard Smith <richard-llvm@metafoo.co.uk> Date: Fri, 12 Jan 2018 22:21:33 +0000 Subject: [PATCH] When rebuilding an InitListExpr, don't give it a type. InitListExprs without types (well, with type 'void') represent not-yet-analyzed initializer lists; InitListExpr with types fool Sema into thinking they don't need further analysis in some cases (particularly C++17 copy omission). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322414 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/TreeTransform.h | 21 +++++-------------- .../cxx1z-initializer-aggregate.cpp | 18 ++++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index ebfdbe83ef..809187f0ae 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -2352,18 +2352,8 @@ public: /// Subclasses may override this routine to provide different behavior. ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, - SourceLocation RBraceLoc, - QualType ResultTy) { - ExprResult Result - = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); - if (Result.isInvalid() || ResultTy->isDependentType()) - return Result; - - // Patch in the result type we were given, which may have been computed - // when the initial InitListExpr was built. - InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); - ILE->setType(ResultTy); - return Result; + SourceLocation RBraceLoc) { + return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); } /// \brief Build a new designated initializer expression. @@ -3394,11 +3384,10 @@ ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, /*IsCall*/true, NewArgs, &ArgChanged)) return ExprError(); - // If this was list initialization, revert to list form. + // If this was list initialization, revert to syntactic list form. if (Construct->isListInitialization()) return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs, - Construct->getLocEnd(), - Construct->getType()); + Construct->getLocEnd()); // Build a ParenListExpr to represent anything else. SourceRange Parens = Construct->getParenOrBraceRange(); @@ -9513,7 +9502,7 @@ TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { } return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, - E->getRBraceLoc(), E->getType()); + E->getRBraceLoc()); } template<typename Derived> diff --git a/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp b/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp index 9110e49f93..f59ec51136 100644 --- a/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp +++ b/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp @@ -112,3 +112,21 @@ namespace Dynamic { // A_CLEANUP: // CHECK: call void @_ZN7Dynamic1AD1Ev({{.*}} @_ZN7Dynamic2d3E } + +namespace Instantiated1 { + struct A { A(); }; + struct B : A { using A::A; }; + template<int> B v({}); + template B v<0>; + // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN13Instantiated11vILi0EEE) { + // CHECK: call void @_ZN13Instantiated11BC1Ev(%{{.*}}* @_ZN13Instantiated11vILi0EEE) +} + +namespace Instantiated2 { + struct A { A(); }; + struct B : A {}; + template<int> B v({}); + template B v<0>; + // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN13Instantiated21vILi0EEE) { + // CHECK: call void @_ZN13Instantiated21AC2Ev( +} -- 2.40.0