<div class="gmail_quote">On Mon, Jun 20, 2011 at 8:10 AM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Jun 19, 2011, at 2:05 AM, Chandler Carruth wrote:<br>
<br>
> Author: chandlerc<br>
> Date: Sun Jun 19 04:05:14 2011<br>
> New Revision: 133383<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=133383&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=133383&view=rev</a><br>
> Log:<br>
> Add test cases for false positives on -Wnull-arithmetic from Richard<br>
> Trieu, and fix them by checking for array and function types as well as<br>
> pointer types.<br>
><br>
> I've added a predicate method on Type to bundle together the logic we're<br>
> using here: isPointerLikeType(). I'd welcome better names for this<br>
> predicate, this is the best I came up with. It's implemented as a switch<br>
> to be a touch lighter weight than all the chained isa<...> casts that<br>
> would result otherwise.<br>
<br>
</div>Comment below about this name…<br>
<div><div></div><div class="h5"><br>
> Modified:<br>
> cfe/trunk/include/clang/AST/Type.h<br>
> cfe/trunk/lib/AST/Type.cpp<br>
> cfe/trunk/lib/Sema/SemaExpr.cpp<br>
> cfe/trunk/test/SemaCXX/null_in_arithmetic_ops.cpp<br>
> cfe/trunk/test/SemaCXX/nullptr_in_arithmetic_ops.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/AST/Type.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=133383&r1=133382&r2=133383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=133383&r1=133382&r2=133383&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/AST/Type.h (original)<br>
> +++ cfe/trunk/include/clang/AST/Type.h Sun Jun 19 04:05:14 2011<br>
> @@ -1373,6 +1373,7 @@<br>
> bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }<br>
> bool isPointerType() const;<br>
> bool isAnyPointerType() const; // Any C pointer or ObjC object pointer<br>
> + bool isPointerLikeType() const;<br>
> bool isBlockPointerType() const;<br>
> bool isVoidPointerType() const;<br>
> bool isReferenceType() const;<br>
><br>
> Modified: cfe/trunk/lib/AST/Type.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=133383&r1=133382&r2=133383&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=133383&r1=133382&r2=133383&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/AST/Type.cpp (original)<br>
> +++ cfe/trunk/lib/AST/Type.cpp Sun Jun 19 04:05:14 2011<br>
> @@ -289,6 +289,31 @@<br>
> }<br>
> }<br>
><br>
> +/// \brief Tests whether the type behaves like a pointer type.<br>
> +///<br>
> +/// This includes all of the obviously pointer types including block pointers,<br>
> +/// member pointers, and ObjC Object pointers. It also includes function and<br>
> +/// array types which behave as pointers due to decay.<br>
> +///<br>
> +/// \returns True for types which act like pointer types.<br>
> +bool Type::isPointerLikeType() const {<br>
> + switch (CanonicalType->getTypeClass()) {<br>
> + case Pointer:<br>
> + case BlockPointer:<br>
> + case MemberPointer:<br>
> + case ConstantArray:<br>
> + case IncompleteArray:<br>
> + case VariableArray:<br>
> + case DependentSizedArray:<br>
> + case FunctionProto:<br>
> + case FunctionNoProto:<br>
> + case ObjCObjectPointer:<br>
> + return true;<br>
> + default:<br>
> + return false;<br>
> + }<br>
> +}<br>
> +<br>
<br>
</div></div>Since this also includes function and array types, I'd like to indicate that in some way… for example<br>
<br>
isPointerLikeRvalueType()<br>
<br>
or<br>
<br>
hasPointerLikeDecayedType()<br></blockquote><div><br></div><div>I really like this name, but I ended up nuking the predicate altogether after talking with John. The user I had in mind was in fact not an appropriate user of it. For now, I suspect 'canDecayToPointerType' will work well as the predicate. Comments on that one appreciated though.</div>
</div>