From 89502c6873c1be53cb183cf57d41a65b74a6bbe6 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Thu, 26 Jul 2018 23:40:42 +0000 Subject: [PATCH] [Sema] Fix a crash by completing a type before using it Only apply this exception on a type that we're able to check. rdar://41903969 Differential revision: https://reviews.llvm.org/D49868 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338089 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaInit.cpp | 1 + ...xx1z-class-template-argument-deduction.cpp | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 9b5a918b71..0dddbdc36f 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -9130,6 +9130,7 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer( Expr *E = ListInit->getInit(0); auto *RD = E->getType()->getAsCXXRecordDecl(); if (!isa(E) && RD && + isCompleteType(Kind.getLocation(), E->getType()) && isOrIsDerivedFromSpecializationOf(RD, Template)) TryListConstructors = false; } diff --git a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp index de61e44a6e..f72cb886d8 100644 --- a/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp +++ b/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp @@ -348,6 +348,31 @@ namespace member_guides { }; } +namespace rdar41903969 { +template struct A {}; +template struct B; +template struct C { + C(A&); + C(B&); +}; + +void foo(A &a, B &b) { + (void)C{b}; + (void)C{a}; +} + +template struct X { + X(std::initializer_list) = delete; + X(const X&); +}; + +template struct D : X {}; + +void bar(D& d) { + (void)X{d}; +} +} + #else // expected-no-diagnostics -- 2.40.0