Commit 5d4e573b by Jason Merrill Committed by Jason Merrill

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.

From-SVN: r251429
parent 11399477
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> 2017-08-23 Jason Merrill <jason@redhat.com>
* lambda.c (build_lambda_object): Check for error_mark_node. * lambda.c (build_lambda_object): Check for error_mark_node.
......
...@@ -100,7 +100,7 @@ ensure_literal_type_for_constexpr_object (tree decl) ...@@ -100,7 +100,7 @@ ensure_literal_type_for_constexpr_object (tree decl)
} }
else 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%> " error ("variable %qD of non-literal type %qT in %<constexpr%> "
"function", decl, type); "function", decl, type);
...@@ -5335,8 +5335,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, ...@@ -5335,8 +5335,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
STRIP_NOPS (x); STRIP_NOPS (x);
if (is_this_parameter (x) && !is_capture_proxy (x)) if (is_this_parameter (x) && !is_capture_proxy (x))
{ {
if (DECL_CONTEXT (x) if (!var_in_maybe_constexpr_fn (x))
&& !DECL_DECLARED_CONSTEXPR_P (DECL_CONTEXT (x)))
{ {
if (flags & tf_error) if (flags & tf_error)
error_at (loc, "use of %<this%> in a constant expression"); error_at (loc, "use of %<this%> in a constant expression");
......
...@@ -5525,9 +5525,10 @@ check_for_uninitialized_const_var (tree decl) ...@@ -5525,9 +5525,10 @@ check_for_uninitialized_const_var (tree decl)
"uninitialized const %qD", decl); "uninitialized const %qD", decl);
else else
{ {
error_at (DECL_SOURCE_LOCATION (decl), if (!is_instantiation_of_constexpr (current_function_decl))
"uninitialized variable %qD in %<constexpr%> function", error_at (DECL_SOURCE_LOCATION (decl),
decl); "uninitialized variable %qD in %<constexpr%> function",
decl);
cp_function_chain->invalid_constexpr = true; cp_function_chain->invalid_constexpr = true;
} }
......
// 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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment