+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>
* semantics.c (finish_omp_clauses): For C_ORT_OMP
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.
On failure, issue diagnostic and return error_mark_node. */
/* FIXME unify with c_fully_fold */
case ASM_EXPR:
if (!ctx->quiet)
- {
- 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");
- }
+ inline_asm_in_constexpr_error (cp_expr_loc_or_input_loc (t));
*non_constant_p = true;
return t;
return false;
case ASM_EXPR:
- /* In C++2a, unevaluated inline assembly is permitted in constexpr
- functions. If it's used in earlier standard modes, we pedwarn in
- cp_parser_asm_definition. */
- return true;
+ if (flags & tf_error)
+ inline_asm_in_constexpr_error (loc);
+ return false;
case OBJ_TYPE_REF:
if (cxx_dialect >= cxx2a)
--- /dev/null
+// 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 ();