PR c++/84938 - ICE with division by ~-1.
authorJason Merrill <jason@redhat.com>
Thu, 5 Apr 2018 00:09:10 +0000 (20:09 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 5 Apr 2018 00:09:10 +0000 (20:09 -0400)
* call.c (set_up_extended_ref_temp): Call cp_fully_fold.

From-SVN: r259108

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/expr/div-by-zero1.C [new file with mode: 0644]

index 62f61eab345425c93d005fe5d162eec13afed69d..22f3e42f0cb66ece2c51050b6f1a55c0dfebebdd 100644 (file)
@@ -1,5 +1,8 @@
 2018-04-04  Jason Merrill  <jason@redhat.com>
 
+       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.
index f81773157b6ee0d012d3589ae4af7bb2e7f1557f..7c99e8ad9100e9d923caaf5895438345b27b926d 100644 (file)
@@ -10869,6 +10869,8 @@ set_up_extended_ref_temp (tree decl, tree expr, vec<tree, va_gc> **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 (file)
index 0000000..63bef40
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/84938
+
+const int &a = 1 / ~-1;                // { dg-warning "division by zero" }