summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard@metafoo.co.uk>2019-12-19 15:18:59 -0800
committerRichard Smith <richard@metafoo.co.uk>2019-12-19 15:20:10 -0800
commitf4a45c2ce4ce2a7a33d5773048682e65f348a486 (patch)
tree5006bf3f2050e83a5f1cc9996ffce05bac7efcb5
parentb284005072122fe4af879725e3c8090009f89ca0 (diff)
downloadbcm5719-llvm-f4a45c2ce4ce2a7a33d5773048682e65f348a486.tar.gz
bcm5719-llvm-f4a45c2ce4ce2a7a33d5773048682e65f348a486.zip
Fix crash on init-capture packs where the type of the initializer is non-dependent.
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp3
-rw-r--r--clang/lib/Sema/SemaTemplateDeduction.cpp3
-rw-r--r--clang/test/CXX/temp/temp.decls/temp.variadic/init-capture.cpp8
-rw-r--r--clang/test/Lexer/cxx-features.cpp4
4 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 14c9ccd8a66..2c7e3a56c04 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 327447746c3..46d92313827 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 4d5b6b47459..ce2fccc8fe6 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 e771d891a14..05f77991fa3 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
OpenPOWER on IntegriCloud