Commit 7c814975 by Marek Polacek Committed by Marek Polacek

constexpr.c (inline_asm_in_constexpr_error): New.

	* constexpr.c (inline_asm_in_constexpr_error): New.
	(cxx_eval_constant_expression) <case ASM_EXPR>: Call it.
	(potential_constant_expression_1) <case ASM_EXPR>: Likewise.

	* g++.dg/cpp2a/inline-asm3.C: New test.

From-SVN: r274210
parent cb0de9b6
2019-08-08 Marek Polacek <polacek@redhat.com>
* constexpr.c (inline_asm_in_constexpr_error): New.
(cxx_eval_constant_expression) <case ASM_EXPR>: Call it.
(potential_constant_expression_1) <case ASM_EXPR>: Likewise.
2019-08-08 Jakub Jelinek <jakub@redhat.com> 2019-08-08 Jakub Jelinek <jakub@redhat.com>
* semantics.c (finish_omp_clauses): For C_ORT_OMP * semantics.c (finish_omp_clauses): For C_ORT_OMP
......
...@@ -4411,6 +4411,17 @@ lookup_placeholder (const constexpr_ctx *ctx, bool lval, tree type) ...@@ -4411,6 +4411,17 @@ lookup_placeholder (const constexpr_ctx *ctx, bool lval, tree type)
return ob; return ob;
} }
/* Complain about an attempt to evaluate inline assembly. */
static void
inline_asm_in_constexpr_error (location_t loc)
{
auto_diagnostic_group d;
error_at (loc, "inline assembly is not a constant expression");
inform (loc, "only unevaluated inline assembly is allowed in a "
"%<constexpr%> function in C++2a");
}
/* Attempt to reduce the expression T to a constant value. /* Attempt to reduce the expression T to a constant value.
On failure, issue diagnostic and return error_mark_node. */ On failure, issue diagnostic and return error_mark_node. */
/* FIXME unify with c_fully_fold */ /* FIXME unify with c_fully_fold */
...@@ -5291,13 +5302,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, ...@@ -5291,13 +5302,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
case ASM_EXPR: case ASM_EXPR:
if (!ctx->quiet) if (!ctx->quiet)
{ inline_asm_in_constexpr_error (cp_expr_loc_or_input_loc (t));
error_at (cp_expr_loc_or_input_loc (t),
"inline assembly is not a constant expression");
inform (cp_expr_loc_or_input_loc (t),
"only unevaluated inline assembly is allowed in a "
"%<constexpr%> function in C++2a");
}
*non_constant_p = true; *non_constant_p = true;
return t; return t;
...@@ -6488,10 +6493,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, ...@@ -6488,10 +6493,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now,
return false; return false;
case ASM_EXPR: case ASM_EXPR:
/* In C++2a, unevaluated inline assembly is permitted in constexpr if (flags & tf_error)
functions. If it's used in earlier standard modes, we pedwarn in inline_asm_in_constexpr_error (loc);
cp_parser_asm_definition. */ return false;
return true;
case OBJ_TYPE_REF: case OBJ_TYPE_REF:
if (cxx_dialect >= cxx2a) if (cxx_dialect >= cxx2a)
......
2019-08-08 Marek Polacek <polacek@redhat.com>
* g++.dg/cpp2a/inline-asm3.C: New test.
2019-08-07 Steven G. Kargl <kargl@gcc.gnu.org> 2019-08-07 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/91359 PR fortran/91359
......
// P1668R1: Permit unevaluated inline asm in constexpr functions
// { dg-do compile { target c++2a } }
// { dg-additional-options "-Wno-pedantic" }
constexpr int
foo ()
{
constexpr int i = ({ asm(""); 42; }); // { dg-error "inline assembly is not a constant expression" }
return i;
}
constexpr int i = foo ();
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