[clang] f4a45c2 - Fix crash on init-capture packs where the type of the initializer is non-dependent.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 19 15:20:19 PST 2019


Author: Richard Smith
Date: 2019-12-19T15:20:10-08:00
New Revision: f4a45c2ce4ce2a7a33d5773048682e65f348a486

URL: https://github.com/llvm/llvm-project/commit/f4a45c2ce4ce2a7a33d5773048682e65f348a486
DIFF: https://github.com/llvm/llvm-project/commit/f4a45c2ce4ce2a7a33d5773048682e65f348a486.diff

LOG: Fix crash on init-capture packs where the type of the initializer is non-dependent.

Added: 
    

Modified: 
    clang/lib/Frontend/InitPreprocessor.cpp
    clang/lib/Sema/SemaTemplateDeduction.cpp
    clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
    clang/test/Lexer/cxx-features.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 14c9ccd8a663..2c7e3a56c043 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -507,7 +507,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const LangOptions &LangOpts,
   if (LangOpts.CPlusPlus14) {
     Builder.defineMacro("__cpp_binary_literals", "201304L");
     Builder.defineMacro("__cpp_digit_separators", "201309L");
-    Builder.defineMacro("__cpp_init_captures", "201304L"); // (not latest)
+    Builder.defineMacro("__cpp_init_captures",
+                        LangOpts.CPlusPlus2a ? "201803L" : "201304L");
     Builder.defineMacro("__cpp_generic_lambdas",
                         LangOpts.CPlusPlus2a ? "201707L" : "201304L");
     Builder.defineMacro("__cpp_decltype_auto", "201304L");

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 327447746c39..46d923138271 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4453,7 +4453,8 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result,
       /*.IsPack = */ (bool)Type.getAs<PackExpansionTypeLoc>()};
 
   if (!DependentDeductionDepth &&
-      (Type.getType()->isDependentType() || Init->isTypeDependent())) {
+      (Type.getType()->isDependentType() || Init->isTypeDependent() ||
+       Init->containsUnexpandedParameterPack())) {
     Result = SubstituteDeducedTypeTransform(*this, DependentResult).Apply(Type);
     assert(!Result.isNull() && "substituting DependentTy can't fail");
     return DAR_Succeeded;

diff  --git a/clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
index 4d5b6b47459c..ce2fccc8fe6f 100644
--- a/clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp
@@ -37,3 +37,11 @@ template<typename ...T> void f(T ...t) {
   }...               // expected-error {{does not contain any unexpanded}}
   );
 }
+
+template<int ...a> constexpr auto x = [...z = a] (auto F) { return F(z...); };
+static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
+static_assert(x<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}
+
+template<int ...a> constexpr auto y = [z = a...] (auto F) { return F(z...); }; // expected-error {{must appear before the name of the capture}}
+static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 123);
+static_assert(y<1,2,3>([](int a, int b, int c) { return 100 * a + 10 * b + c; }) == 124); // expected-error {{failed}}

diff  --git a/clang/test/Lexer/cxx-features.cpp b/clang/test/Lexer/cxx-features.cpp
index e771d891a14b..05f77991fa34 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -66,6 +66,8 @@
 #error "wrong value for __cpp_impl_three_way_comparison"
 #endif
 
+// init_captures checked below
+
 // --- C++17 features ---
 
 #if check(hex_float, 0, 0, 0, 201603, 201603)
@@ -170,7 +172,7 @@
 #error "wrong value for __cpp_digit_separators"
 #endif
 
-#if check(init_captures, 0, 0, 201304, 201304, 201304)
+#if check(init_captures, 0, 0, 201304, 201304, 201803)
 #error "wrong value for __cpp_init_captures"
 #endif
 


        


More information about the cfe-commits mailing list