History log of /external/clang/test/SemaCXX/warn-div-or-rem-by-zero.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
93f32da079874f70857af42eb9be382f307d4f1e 14-Jun-2013 Chandler Carruth <chandlerc@gmail.com> Fix the warning for divide by zero to be a bit more robust. ;]

Previously, it only ever fired for zeros which formed null pointers.
Now, hilariously, in C++98 this was almost anything. Including tricks
like warning on the divisor in this code:

typedef char c3[3];
size_t f(c3* ptr) {
return (sizeof(ptr) / sizeof(*ptr)) / (size_t)(!(sizeof(ptr) % sizeof(*ptr)));
}

Why the RHS of the outer divide is a null pointer constant is a sordid
tale of sorrow. Anyways, the committee fixed this for C++11 and onward
as part of core isssue 903, and Richard recently implemented this fix
causing the warning to go away here (and elsewhere).

This patch restores the warning here and adds it for numerous other
somewhat obvious gaffes:

int g(int x) {
return x / (int)(0.0);
}

The patch is essentially just using the full power of our constant
folding in Clang to produce the warning, but insisting that it must fold
to an *integer* which is zero so that we don't get false positives
anywhere.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183970 91177308-0d34-0410-b5e6-96231b3b80d8
/external/clang/test/SemaCXX/warn-div-or-rem-by-zero.cpp