From: Marek Polacek Date: Thu, 8 Aug 2019 14:55:52 +0000 (+0000) Subject: constexpr.c (inline_asm_in_constexpr_error): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7c81497574411797ac55b9abfab1275bf3241078;p=gcc.git constexpr.c (inline_asm_in_constexpr_error): New. * constexpr.c (inline_asm_in_constexpr_error): New. (cxx_eval_constant_expression) : Call it. (potential_constant_expression_1) : Likewise. * g++.dg/cpp2a/inline-asm3.C: New test. From-SVN: r274210 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f937bf5eb32..3af901c78ea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-08-08 Marek Polacek + + * constexpr.c (inline_asm_in_constexpr_error): New. + (cxx_eval_constant_expression) : Call it. + (potential_constant_expression_1) : Likewise. + 2019-08-08 Jakub Jelinek * semantics.c (finish_omp_clauses): For C_ORT_OMP diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index e86b0789b84..23f2a027e2f 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -4411,6 +4411,17 @@ lookup_placeholder (const constexpr_ctx *ctx, bool lval, tree type) 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 " + "% 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 */ @@ -5291,13 +5302,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, 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 " - "% function in C++2a"); - } + inline_asm_in_constexpr_error (cp_expr_loc_or_input_loc (t)); *non_constant_p = true; return t; @@ -6488,10 +6493,9 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, 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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 685f3731cb7..be085243d37 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-08-08 Marek Polacek + + * g++.dg/cpp2a/inline-asm3.C: New test. + 2019-08-07 Steven G. Kargl PR fortran/91359 diff --git a/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C b/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C new file mode 100644 index 00000000000..b636e3b2d87 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/inline-asm3.C @@ -0,0 +1,12 @@ +// 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 ();