Fix bug where types other than 'cv auto', 'cv auto &', and 'cv auto &&' could

incorrectly be deduced from an initializer list in pathological cases.

llvm-svn: 291191
This commit is contained in:
Richard Smith 2017-01-05 23:12:16 +00:00
parent c92d206ce4
commit c8a32e5ed2
2 changed files with 16 additions and 0 deletions

View File

@ -4127,6 +4127,12 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
InitListExpr *InitList = dyn_cast<InitListExpr>(Init);
if (InitList) {
// Notionally, we substitute std::initializer_list<T> for 'auto' and deduce
// against that. Such deduction only succeeds if removing cv-qualifiers and
// references results in std::initializer_list<T>.
if (!Type.getType().getNonReferenceType()->getAs<AutoType>())
return DAR_Failed;
for (unsigned i = 0, e = InitList->getNumInits(); i < e; ++i) {
if (DeduceTemplateArgumentsFromCallArgument(
*this, TemplateParamsSt.get(), TemplArg, InitList->getInit(i),

View File

@ -337,3 +337,13 @@ namespace update_rbrace_loc_crash {
Explode<ContainsIncomplete, 4>([](int) {});
}
}
namespace no_conversion_after_auto_list_deduction {
// We used to deduce 'auto' == 'std::initializer_list<X>' here, and then
// incorrectly accept the declaration of 'x'.
struct X { using T = std::initializer_list<X> X::*; operator T(); };
auto X::*x = { X() }; // expected-error {{from initializer list}}
struct Y { using T = std::initializer_list<Y>(*)(); operator T(); };
auto (*y)() = { Y() }; // expected-error {{from initializer list}}
}