Seems that people find compile-time error on the following testcase overly
pedantic.  I.e. that "enum A { X = -1 << 1 };" should compile, at least with
-fpermissive.  So I've changed the error_at into permerror and the return value
of cxx_eval_check_shift_p now depends on flag_permissive.  Luckily, I didn't
have to modify any of the existing tests.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-01-12  Marek Polacek  <pola...@redhat.com>

        PR c++/68979
        * constexpr.c (cxx_eval_check_shift_p): Use permerror rather than
        error_at and return negated flag_permissive.

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

diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c
index e60180e..dbcc242 100644
--- gcc/cp/constexpr.c
+++ gcc/cp/constexpr.c
@@ -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;
     }
   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;
     }
 
   /* 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;
        }
       /* 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;
        }
     }
   return false;
diff --git gcc/testsuite/g++.dg/warn/permissive-1.C 
gcc/testsuite/g++.dg/warn/permissive-1.C
index e69de29..7223e68 100644
--- gcc/testsuite/g++.dg/warn/permissive-1.C
+++ gcc/testsuite/g++.dg/warn/permissive-1.C
@@ -0,0 +1,8 @@
+// PR c++/68979
+// { dg-do compile }
+// { 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 << 100 }; // { dg-warning "operand of shift expression" }
+enum D { DD = 31 << 30 }; // { dg-warning "shift expression" "" { target c++11 
} }

        Marek

Reply via email to