From a7ec7182dbbd85f14dd5d9f4adb5f16faed9581d Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 4 Apr 2018 20:09:10 -0400 Subject: [PATCH] PR c++/84938 - ICE with division by ~-1. * call.c (set_up_extended_ref_temp): Call cp_fully_fold. From-SVN: r259108 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/call.c | 2 ++ gcc/testsuite/g++.dg/expr/div-by-zero1.C | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 gcc/testsuite/g++.dg/expr/div-by-zero1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 62f61eab345..22f3e42f0cb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2018-04-04 Jason Merrill + PR c++/84938 - ICE with division by ~-1. + * call.c (set_up_extended_ref_temp): Call cp_fully_fold. + PR c++/84936 - ICE with unexpanded pack in mem-initializer. * parser.c (cp_parser_mem_initializer_list): Call check_for_bare_parameter_packs. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f81773157b6..7c99e8ad910 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -10869,6 +10869,8 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups, /* If the initializer is constant, put it in DECL_INITIAL so we get static initialization and use in constant expressions. */ init = maybe_constant_init (expr); + /* As in store_init_value. */ + init = cp_fully_fold (init); if (TREE_CONSTANT (init)) { if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type)) diff --git a/gcc/testsuite/g++.dg/expr/div-by-zero1.C b/gcc/testsuite/g++.dg/expr/div-by-zero1.C new file mode 100644 index 00000000000..63bef406408 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/div-by-zero1.C @@ -0,0 +1,3 @@ +// PR c++/84938 + +const int &a = 1 / ~-1; // { dg-warning "division by zero" } -- 2.30.2