From d8cff23f65befa76082b54bd478c0b9299255788 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 1 Mar 2018 17:08:35 +0000 Subject: [PATCH] re PR c++/84596 (internal compiler error: unexpected expression '(bool)c' of kind implicit_conv_expr (cxx_eval_constant_expression)) PR c++/84596 * constexpr.c (require_rvalue_constant_expression): New function. * cp-tree.h: Declare it. * semantics.c (finish_static_assert): Use it instead of require_potential_rvalue_constant_expression. * g++.dg/cpp0x/static_assert14.C: New test. From-SVN: r258107 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/constexpr.c | 15 +++++++++++++-- gcc/cp/cp-tree.h | 1 + gcc/cp/semantics.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/static_assert14.C | 7 +++++++ 6 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/static_assert14.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a6deacb13f1..acaabd0e197 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-03-01 Marek Polacek + + PR c++/84596 + * constexpr.c (require_rvalue_constant_expression): New function. + * cp-tree.h: Declare it. + * semantics.c (finish_static_assert): Use it instead of + require_potential_rvalue_constant_expression. + 2018-03-01 Jason Merrill Alexandre Oliva diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 4bbdbf43487..39e6cdfb33d 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -6047,7 +6047,8 @@ potential_rvalue_constant_expression (tree t) bool require_potential_constant_expression (tree t) { - return potential_constant_expression_1 (t, false, true, false, tf_warning_or_error); + return potential_constant_expression_1 (t, false, true, false, + tf_warning_or_error); } /* Cross product of the above. */ @@ -6055,7 +6056,17 @@ require_potential_constant_expression (tree t) bool require_potential_rvalue_constant_expression (tree t) { - return potential_constant_expression_1 (t, true, true, false, tf_warning_or_error); + return potential_constant_expression_1 (t, true, true, false, + tf_warning_or_error); +} + +/* Like above, but don't consider PARM_DECL a potential_constant_expression. */ + +bool +require_rvalue_constant_expression (tree t) +{ + return potential_constant_expression_1 (t, true, true, true, + tf_warning_or_error); } /* Like potential_constant_expression, but don't consider possible constexpr diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 743dd340245..17d8c6d2650 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7409,6 +7409,7 @@ extern bool is_static_init_expression (tree); extern bool potential_rvalue_constant_expression (tree); extern bool require_potential_constant_expression (tree); extern bool require_constant_expression (tree); +extern bool require_rvalue_constant_expression (tree); extern bool require_potential_rvalue_constant_expression (tree); extern tree cxx_constant_value (tree, tree = NULL_TREE); extern tree cxx_constant_init (tree, tree = NULL_TREE); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 35569d0cb0d..87c5c669a55 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -8671,7 +8671,7 @@ finish_static_assert (tree condition, tree message, location_t location, else if (condition && condition != error_mark_node) { error ("non-constant condition for static assertion"); - if (require_potential_rvalue_constant_expression (condition)) + if (require_rvalue_constant_expression (condition)) cxx_constant_value (condition); } input_location = saved_loc; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7a45412179d..bcb40bad793 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-03-01 Marek Polacek + + PR c++/84596 + * g++.dg/cpp0x/static_assert14.C: New test. + 2018-03-01 Paolo Carlini PR c++/79410 diff --git a/gcc/testsuite/g++.dg/cpp0x/static_assert14.C b/gcc/testsuite/g++.dg/cpp0x/static_assert14.C new file mode 100644 index 00000000000..ee709f4200f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/static_assert14.C @@ -0,0 +1,7 @@ +// PR c++/84596 +// { dg-do compile { target c++11 } } + +template +void b(int c) { + static_assert (c, "c"); // { dg-error "non-constant|not a constant" } +} -- 2.30.2