PR c++/91819 - ICE with operator++ and enum.
authorMarek Polacek <polacek@redhat.com>
Sun, 22 Sep 2019 12:35:00 +0000 (12:35 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Sun, 22 Sep 2019 12:35:00 +0000 (12:35 +0000)
* call.c (build_new_op_1): Set arg2_type.

* g++.dg/other/operator4.C: New test.

From-SVN: r276027

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/operator4.C [new file with mode: 0644]

index 3015d6806d08c24873897b661318af66b73354ea..4420d8ffab7d1ba045ec1a8a81921a3e28c1489b 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91819 - ICE with operator++ and enum.
+       * call.c (build_new_op_1): Set arg2_type.
+
 2019-09-17  Jason Merrill  <jason@redhat.com>
 
        * parser.c (cp_parser_statement): Handle [[likely]] on
index e613d8a006617c10f0167446d66dd2235a87e81a..2dad699622e9f48e9cb09fdf01020e709077d291 100644 (file)
@@ -5878,7 +5878,10 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags,
     goto builtin;
 
   if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
-    arg2 = integer_zero_node;
+    {
+      arg2 = integer_zero_node;
+      arg2_type = integer_type_node;
+    }
 
   vec_alloc (arglist, 3);
   arglist->quick_push (arg1);
index 412616d8f33efb0af1417eeffdf909d57258cfc6..cbf0eff988c326065cf7cee2da65f32eae0db6a5 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-22  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/91819 - ICE with operator++ and enum.
+       * g++.dg/other/operator4.C: New test.
+
 2019-09-21  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/91830
diff --git a/gcc/testsuite/g++.dg/other/operator4.C b/gcc/testsuite/g++.dg/other/operator4.C
new file mode 100644 (file)
index 0000000..e7a41c0
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/91819 - ICE with operator++ and enum.
+// { dg-do compile }
+
+enum Foo
+{
+  a,
+  b
+};
+
+inline Foo operator++(Foo &f, int) 
+{
+  return f = (Foo)(f + 1);
+}
+
+int main()
+{
+  int count = 0;
+  for (Foo f = a; f <= b; f++) {
+    count++;
+  }
+  return count;
+}