[cfe-commits] patch: implement nonnull on overloaded binary operators
Nick Lewycky
nlewycky at google.com
Wed Jan 23 17:56:51 PST 2013
On 23 January 2013 17:52, Matt Beaumont-Gay <matthewbg at google.com> wrote:
> + // Cut off the implicit 'this'.
> + if (isa<CXXMethodDecl>(FnDecl))
> + ArgsArray = ArgsArray.slice(1);
>
> What about static methods?
>
nonnull.cc:4:15: error: overloaded 'operator<' cannot be a static member
function
static bool operator<(const X&, const char*) __attribute__((nonnull(2)));
^
I can declare a static non-member, but that makes it a free function, which
works fine:
static bool operator>(const X&, const char*) __attribute__((nonnull(2)));
[...]
nonnull.cc:15:12: warning: null passed to a callee which requires a non-null
argument [-Wnonnull]
(void)(x > 0);
^ ~
In this case the logic is copied from Sema::CheckFunctionCall in
SemaChecking.cpp:
bool IsMemberOperatorCall = isa<CXXOperatorCallExpr>(TheCall) &&
isa<CXXMethodDecl>(FDecl);
[...]
if (IsMemberOperatorCall) {
// If this is a call to a member operator, hide the first argument
// from checkCall.
// FIXME: Our choice of AST representation here is less than ideal.
++Args;
--NumArgs;
}
but I don't need to test for CXXOperatorCallExpr since we know we just
created one.
Nick
On Wed, Jan 23, 2013 at 5:15 PM, Nick Lewycky <nlewycky at google.com> wrote:
> > GCC supports attribute nonnull on overloaded operators, but clang
> doesn't.
> > This patch adds support to the code path around binary operators, as I
> don't
> > think it's possible to make it fire on overloaded unary operators.
> >
> > Please review!
> >
> > Nick
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130123/a45ed50a/attachment.html>
More information about the cfe-commits
mailing list