]> granicus.if.org Git - clang/commitdiff
use DiagRuntimeBehavior to silence the div/rem by zero warning when
authorChris Lattner <sabre@nondot.org>
Tue, 12 Jan 2010 21:30:55 +0000 (21:30 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 12 Jan 2010 21:30:55 +0000 (21:30 +0000)
not in an evaluated context.  This removes some bogus warnings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93258 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/exprs.c
test/SemaTemplate/instantiate-expr-1.cpp
test/SemaTemplate/instantiate-static-var.cpp

index 7dc13c4ad86ceeee7913f20a639a92a363808ca4..26c2e176cf01de2684a4e672ab7c1de8f0eaaf8a 100644 (file)
@@ -4868,7 +4868,8 @@ QualType Sema::CheckMultiplyDivideOperands(
   // Check for division by zero.
   if (isDiv &&
       rex->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
-    Diag(Loc, diag::warn_division_by_zero) << rex->getSourceRange();
+    DiagRuntimeBehavior(Loc, PDiag(diag::warn_division_by_zero) 
+                                     << rex->getSourceRange());
   
   return compType;
 }
@@ -4888,7 +4889,8 @@ QualType Sema::CheckRemainderOperands(
   
   // Check for remainder by zero.
   if (rex->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
-    Diag(Loc, diag::warn_remainder_by_zero) << rex->getSourceRange();
+    DiagRuntimeBehavior(Loc, PDiag(diag::warn_remainder_by_zero)
+                                 << rex->getSourceRange());
   
   return compType;
 }
index b2f92e2c01ffd9cb20e1d5e05ac72491a833e629..9059cac22e508111e10a1d937798a331599b2be2 100644 (file)
@@ -120,5 +120,7 @@ void test17(int x) {
   x = x % 0;  // expected-warning {{remainder by zero is undefined}}
   x /= 0;  // expected-warning {{division by zero is undefined}}
   x %= 0;  // expected-warning {{remainder by zero is undefined}}
+  
+  x = sizeof(x/0);  // no warning.
 }
 
index 5752033fbd364f2924bc432f79a6f6ac2811b3de..663749ddce5b678f2af7c27a0273bea11c00cf02 100644 (file)
@@ -35,8 +35,7 @@ void test_BitfieldMinus() {
 template<int I, int J>
 struct BitfieldDivide {
   int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
-                        // expected-note{{division by zero}} \
-                        // expected-warning {{division by zero is undefined}}
+                        // expected-note{{division by zero}}
 };
 
 void test_BitfieldDivide() {
index 1fcc36b43cc258c149f8525dd80b7371efcece05..789fe3db872ee01ff2478f08a830ac0689b25138 100644 (file)
@@ -2,7 +2,7 @@
 template<typename T, T Divisor>
 class X {
 public:
-  static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} expected-warning {{division by zero is undefined}}
+  static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}}
 };
 
 int array1[X<int, 2>::value == 5? 1 : -1];