summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/null_in_arithmetic_ops.cpp
Commit message (Collapse)AuthorAgeFilesLines
* PR16074, implement warnings to catch pointer to boolean true and pointer toRichard Trieu2014-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | null comparison when the pointer is known to be non-null. This catches the array to pointer decay, function to pointer decay and address of variables. This does not catch address of function since this has been previously used to silence a warning. Pointer to bool conversion is under -Wbool-conversion. Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group of -Wtautological-compare. void foo() { int arr[5]; int x; // warn on these conditionals if (foo); if (arr); if (&x); if (foo == null); if (arr == null); if (&x == null); if (&foo); // no warning } llvm-svn: 202216
* PR14284: crash on ext-valid returning NULL from a void functionDavid Blaikie2012-11-081-0/+2
| | | | llvm-svn: 167565
* Add -Wstring-plus-int, which warns on "str" + int and int + "str".Nico Weber2012-03-021-1/+1
| | | | | | | | It doesn't warn if the integer is known at compile time and within the bounds of the string. Discussion: http://comments.gmane.org/gmane.comp.compilers.clang.scm/47203 llvm-svn: 151943
* The current warning in -Wnull-arithmetic for comparisons between NULL and ↵Richard Trieu2011-08-111-7/+7
| | | | | | | | | | | | | | | | | non-pointers is not very helpful. This patch will update the wording to be more helpful to users. Old warning: warning: use of NULL in arithmetic operation [-Wnull-arithmetic] return 10 <= NULL; ^ ~~~~ New warning: warning: comparison between NULL and non-pointer ('int' and NULL) [-Wnull-arithmetic] return 10 <= NULL; ~~ ^ ~~~~ llvm-svn: 137377
* Factor out (some of) the checking for invalid forms of pointerChandler Carruth2011-06-271-1/+1
| | | | | | | | | | | | | | | | | | | arithmetic into a couple of common routines. Use these to make the messages more consistent in the various contexts, especially in terms of consistently diagnosing binary operators with invalid types on both the left- and right-hand side. Also, improve the grammar and wording of the messages some, handling both two pointers and two (different) types. The wording of function pointer arithmetic diagnostics still strikes me as poorly phrased, and I worry this makes them slightly more awkward if more consistent. I'm hoping to fix that with a follow-on patch and test case that will also make them more helpful when a typedef or template type parameter makes the type completely opaque. Suggestions on better wording are very welcome, thanks to Richard Smith for some initial help on that front. llvm-svn: 133906
* Use an explicitly 64-bit triple flag to ensure we can easily verify theChandler Carruth2011-06-201-1/+1
| | | | | | | | | | types printed in various diagnostics. We could omit checking for the types, but that can mask errors where the wrong type is streamed into the diagnostic. There was at least one of these caught by this test already. llvm-svn: 133429
* Fix a problem with the diagnostics of invalid arithmetic with functionChandler Carruth2011-06-201-1/+1
| | | | | | | | pointers I found while working on the NULL arithmetic warning. We here always assuming the LHS was the pointer, instead of using the selected pointer expression. llvm-svn: 133428
* Move away from the poor "abstraction" I added to Type. John arguedChandler Carruth2011-06-201-8/+20
| | | | | | | | | | | | | | effectively that this abstraction simply doesn't exist. That is highlighted by the fact that by using it we were papering over a more serious error in this warning: the fact that we warned for *invalid* constructs involving member pointers and block pointers. I've fixed the obvious issues with the warning here, but this is confirming an original suspicion that this warning's implementation is flawed. I'm looking into how we can implement this more reasonably. WIP on that front. llvm-svn: 133425
* Add test cases for false positives on -Wnull-arithmetic from RichardChandler Carruth2011-06-191-0/+11
| | | | | | | | | | | | | Trieu, and fix them by checking for array and function types as well as pointer types. I've added a predicate method on Type to bundle together the logic we're using here: isPointerLikeType(). I'd welcome better names for this predicate, this is the best I came up with. It's implemented as a switch to be a touch lighter weight than all the chained isa<...> casts that would result otherwise. llvm-svn: 133383
* Put the new warning from revision 133196 on NULL arithmetic behind the flag ↵Richard Trieu2011-06-171-1/+1
| | | | | | -Wnull-arthimetic and set to DefaultIgnore. A few edge cases need to be worked out before this can be set to default. llvm-svn: 133287
* Add a new warning when a NULL constant is used in arithmetic operations. ↵Richard Trieu2011-06-161-0/+70
The warning will fire on cases such as: int x = 1 + NULL; llvm-svn: 133196
OpenPOWER on IntegriCloud