зеркало из https://github.com/microsoft/clang-1.git
use DiagRuntimeBehavior to silence the div/rem by zero warning when
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
This commit is contained in:
Родитель
84d0a19828
Коммит
cb329c506d
|
@ -4868,7 +4868,8 @@ QualType Sema::CheckMultiplyDivideOperands(
|
||||||
// Check for division by zero.
|
// Check for division by zero.
|
||||||
if (isDiv &&
|
if (isDiv &&
|
||||||
rex->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
|
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;
|
return compType;
|
||||||
}
|
}
|
||||||
|
@ -4888,7 +4889,8 @@ QualType Sema::CheckRemainderOperands(
|
||||||
|
|
||||||
// Check for remainder by zero.
|
// Check for remainder by zero.
|
||||||
if (rex->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNotNull))
|
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;
|
return compType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,5 +120,7 @@ void test17(int x) {
|
||||||
x = x % 0; // expected-warning {{remainder by zero is undefined}}
|
x = x % 0; // expected-warning {{remainder by zero is undefined}}
|
||||||
x /= 0; // expected-warning {{division by zero is undefined}}
|
x /= 0; // expected-warning {{division by zero is undefined}}
|
||||||
x %= 0; // expected-warning {{remainder by zero is undefined}}
|
x %= 0; // expected-warning {{remainder by zero is undefined}}
|
||||||
|
|
||||||
|
x = sizeof(x/0); // no warning.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ void test_BitfieldMinus() {
|
||||||
template<int I, int J>
|
template<int I, int J>
|
||||||
struct BitfieldDivide {
|
struct BitfieldDivide {
|
||||||
int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
|
int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
|
||||||
// expected-note{{division by zero}} \
|
// expected-note{{division by zero}}
|
||||||
// expected-warning {{division by zero is undefined}}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_BitfieldDivide() {
|
void test_BitfieldDivide() {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
template<typename T, T Divisor>
|
template<typename T, T Divisor>
|
||||||
class X {
|
class X {
|
||||||
public:
|
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];
|
int array1[X<int, 2>::value == 5? 1 : -1];
|
||||||
|
|
Загрузка…
Ссылка в новой задаче