+2017-08-28 Jason Merrill <jason@redhat.com>
+
+ PR c++/80935 - wrong C++17 error with lambda
+ * decl.c (check_for_uninitialized_const_var): Check
+ is_instantiation_of_constexpr.
+ * constexpr.c (ensure_literal_type_for_constexpr_object): Check
+ is_instantiation_of_constexpr.
+ (potential_constant_expression_1): Check var_in_maybe_constexpr_fn.
+
2017-08-23 Jason Merrill <jason@redhat.com>
* lambda.c (build_lambda_object): Check for error_mark_node.
}
else
{
- if (!DECL_TEMPLATE_INSTANTIATION (current_function_decl))
+ if (!is_instantiation_of_constexpr (current_function_decl))
{
error ("variable %qD of non-literal type %qT in %<constexpr%> "
"function", decl, type);
STRIP_NOPS (x);
if (is_this_parameter (x) && !is_capture_proxy (x))
{
- if (DECL_CONTEXT (x)
- && !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
+ if (!var_in_maybe_constexpr_fn (x))
{
if (flags & tf_error)
error_at (loc, "use of %<this%> in a constant expression");
"uninitialized const %qD", decl);
else
{
- error_at (DECL_SOURCE_LOCATION (decl),
- "uninitialized variable %qD in %<constexpr%> function",
- decl);
+ if (!is_instantiation_of_constexpr (current_function_decl))
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "uninitialized variable %qD in %<constexpr%> function",
+ decl);
cp_function_chain->invalid_constexpr = true;
}
--- /dev/null
+// PR c++/80642
+// { dg-do compile { target c++14 } }
+
+int main()
+{
+ [](auto i)
+ {
+ if (i)
+ {
+ int j;
+ static int k;
+ return i + j;
+ }
+ return i;
+ }(0);
+}