]> granicus.if.org Git - clang/commitdiff
Fix bug where types other than 'cv auto', 'cv auto &', and 'cv auto &&' could
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jan 2017 23:12:16 +0000 (23:12 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 5 Jan 2017 23:12:16 +0000 (23:12 +0000)
incorrectly be deduced from an initializer list in pathological cases.

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

lib/Sema/SemaTemplateDeduction.cpp
test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

index 043e5c37160f0044d57d41b7061cfded8fe44e61..b79904c0a703c6ac507e6875c8146c54c2e91c3a 100644 (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),
index 01d498a5e95b6c840ac0dd4e8dd3dd1529c1455c..9b8fadd2f522693c1249ff2c34eeb52c25d95027 100644 (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}}
+}