]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/68979
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jan 2016 16:48:29 +0000 (16:48 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 12 Jan 2016 16:48:29 +0000 (16:48 +0000)
* constexpr.c (cxx_eval_check_shift_p): Use permerror rather than
error_at and adjust the return value.

* g++.dg/warn/permissive-1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232280 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/permissive-1.C [new file with mode: 0644]

index 363f6cd6cd56db9cdbcec24e7b198ae2da04d349..7230c718c42b7b13c13bd5428b7bfdd0713572b3 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/68979
+       * constexpr.c (cxx_eval_check_shift_p): Use permerror rather than
+       error_at and adjust the return value.
+
 2016-01-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR objc++/68511
index e60180ee6cdc7ac083bc4d44539f5b4c7952ab69..36a1e4286dfb23c9a6b6c28c27eccef580a8c1c1 100644 (file)
@@ -1512,17 +1512,17 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx,
   if (tree_int_cst_sgn (rhs) == -1)
     {
       if (!ctx->quiet)
-       error_at (loc, "right operand of shift expression %q+E is negative",
-                 build2_loc (loc, code, type, lhs, rhs));
-      return true;
+       permerror (loc, "right operand of shift expression %q+E is negative",
+                  build2_loc (loc, code, type, lhs, rhs));
+      return (!flag_permissive || ctx->quiet);
     }
   if (compare_tree_int (rhs, uprec) >= 0)
     {
       if (!ctx->quiet)
-       error_at (loc, "right operand of shift expression %q+E is >= than "
-                 "the precision of the left operand",
-                 build2_loc (loc, code, type, lhs, rhs));
-      return true;
+       permerror (loc, "right operand of shift expression %q+E is >= than "
+                  "the precision of the left operand",
+                  build2_loc (loc, code, type, lhs, rhs));
+      return (!flag_permissive || ctx->quiet);
     }
 
   /* The value of E1 << E2 is E1 left-shifted E2 bit positions; [...]
@@ -1536,9 +1536,10 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx,
       if (tree_int_cst_sgn (lhs) == -1)
        {
          if (!ctx->quiet)
-           error_at (loc, "left operand of shift expression %q+E is negative",
-                     build2_loc (loc, code, type, lhs, rhs));
-         return true;
+           permerror (loc,
+                      "left operand of shift expression %q+E is negative",
+                      build2_loc (loc, code, type, lhs, rhs));
+         return (!flag_permissive || ctx->quiet);
        }
       /* For signed x << y the following:
         (unsigned) x >> ((prec (lhs) - 1) - y)
@@ -1555,9 +1556,9 @@ cxx_eval_check_shift_p (location_t loc, const constexpr_ctx *ctx,
       if (tree_int_cst_lt (integer_one_node, t))
        {
          if (!ctx->quiet)
-           error_at (loc, "shift expression %q+E overflows",
-                     build2_loc (loc, code, type, lhs, rhs));
-         return true;
+           permerror (loc, "shift expression %q+E overflows",
+                      build2_loc (loc, code, type, lhs, rhs));
+         return (!flag_permissive || ctx->quiet);
        }
     }
   return false;
index 5eba1a19bf70702da4c9c3c30818e7e34ff12483..ec887e975056672d3ee7deb5ffe1546af39e990d 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/68979
+       * g++.dg/warn/permissive-1.C: New test.
+
 2016-01-12  Jakub Jelinek  <jakub@redhat.com>
 
        PR objc++/68511
diff --git a/gcc/testsuite/g++.dg/warn/permissive-1.C b/gcc/testsuite/g++.dg/warn/permissive-1.C
new file mode 100644 (file)
index 0000000..bfaca76
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/68979
+// { dg-do compile { target int32 } }
+// { dg-options "-fpermissive -Wno-shift-overflow -Wno-shift-count-overflow -Wno-shift-count-negative" }
+
+enum A { AA = -1 << 4 }; // { dg-warning "operand of shift expression" "" { target c++11 } }
+enum B { BB = 1 << -4 }; // { dg-warning "operand of shift expression" }
+enum C { CC = 1 << __SIZEOF_INT__ * 4 * __CHAR_BIT__ - 4 }; // { dg-warning "operand of shift expression" }
+enum D { DD = 10 << __SIZEOF_INT__ * __CHAR_BIT__ - 2 }; // { dg-warning "shift expression" "" { target c++11 } }