Commit 9638f320 by Paolo Carlini Committed by Paolo Carlini

re PR c++/81054 (ICE with volatile variable in constexpr function)

/cp
2018-01-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81054
	* constexpr.c (ensure_literal_type_for_constexpr_object): Return
	error_mark_node when we give an error.
	* decl.c (cp_finish_decl): Use the latter.

/testsuite
2018-01-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/81054
	* g++.dg/cpp0x/constexpr-ice19.C: New.

From-SVN: r256816
parent 95f94b38
2018-01-17 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/81054
* constexpr.c (ensure_literal_type_for_constexpr_object): Return
error_mark_node when we give an error.
* decl.c (cp_finish_decl): Use the latter.
2018-01-17 Nathan Sidwell <nathan@acm.org> 2018-01-17 Nathan Sidwell <nathan@acm.org>
PR c++/83287 PR c++/83287
......
...@@ -75,7 +75,8 @@ literal_type_p (tree t) ...@@ -75,7 +75,8 @@ literal_type_p (tree t)
} }
/* If DECL is a variable declared `constexpr', require its type /* If DECL is a variable declared `constexpr', require its type
be literal. Return the DECL if OK, otherwise NULL. */ be literal. Return error_mark_node if we give an error, the
DECL otherwise. */
tree tree
ensure_literal_type_for_constexpr_object (tree decl) ensure_literal_type_for_constexpr_object (tree decl)
...@@ -97,6 +98,7 @@ ensure_literal_type_for_constexpr_object (tree decl) ...@@ -97,6 +98,7 @@ ensure_literal_type_for_constexpr_object (tree decl)
error ("the type %qT of %<constexpr%> variable %qD " error ("the type %qT of %<constexpr%> variable %qD "
"is not literal", type, decl); "is not literal", type, decl);
explain_non_literal_class (type); explain_non_literal_class (type);
decl = error_mark_node;
} }
else else
{ {
...@@ -105,10 +107,10 @@ ensure_literal_type_for_constexpr_object (tree decl) ...@@ -105,10 +107,10 @@ ensure_literal_type_for_constexpr_object (tree 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);
explain_non_literal_class (type); explain_non_literal_class (type);
decl = error_mark_node;
} }
cp_function_chain->invalid_constexpr = true; cp_function_chain->invalid_constexpr = true;
} }
return NULL;
} }
} }
return decl; return decl;
......
...@@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, ...@@ -6810,8 +6810,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
cp_apply_type_quals_to_decl (cp_type_quals (type), decl); cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
} }
if (!ensure_literal_type_for_constexpr_object (decl)) if (ensure_literal_type_for_constexpr_object (decl)
DECL_DECLARED_CONSTEXPR_P (decl) = 0; == error_mark_node)
{
DECL_DECLARED_CONSTEXPR_P (decl) = 0;
return;
}
if (VAR_P (decl) if (VAR_P (decl)
&& DECL_CLASS_SCOPE_P (decl) && DECL_CLASS_SCOPE_P (decl)
......
// PR c++/81054
// { dg-do compile { target c++11 } }
struct A
{
volatile int i;
constexpr A() : i() {}
};
struct B
{
static constexpr A a {}; // { dg-error "not literal" }
};
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