diff options
author | Marek Polacek <polacek@redhat.com> | 2019-08-08 14:55:52 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2019-08-08 14:55:52 +0000 |
commit | 7c81497574411797ac55b9abfab1275bf3241078 (patch) | |
tree | e5e389ec951d66518978ff3b9fb8a093647175ac /gcc/cp | |
parent | cb0de9b60cdc362915e06dfe8a373205d93b232d (diff) | |
download | gcc-7c81497574411797ac55b9abfab1275bf3241078.zip gcc-7c81497574411797ac55b9abfab1275bf3241078.tar.gz gcc-7c81497574411797ac55b9abfab1275bf3241078.tar.bz2 |
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
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 26 |
2 files changed, 21 insertions, 11 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f937bf5..3af901c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +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 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index e86b078..23f2a02 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 " + "%<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 */ @@ -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 " - "%<constexpr%> 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) |