[PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc
Andy Kaylor via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 30 15:46:04 PDT 2017
andrew.w.kaylor added inline comments.
================
Comment at: lib/AST/Expr.cpp:1857
+ if (!PExp->IgnoreParenCasts()
+ ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNull))
+ return false;
----------------
rsmith wrote:
> If we get here with a value-dependent expression, we should treat it as non-null (do not warn on `(char*)PtrTemplateParameter + N`).
OK. I wasn't sure about that.
So how do I test that? Is this right?
```
template<typename T, T *P>
T* f(intptr_t offset) {
return P + offset;
}
char *test(intptr_t offset) {
return f<char, nullptr>(offset);
}
```
================
Comment at: lib/Sema/SemaExpr.cpp:8877
if (RHS.get()->getType()->isIntegerType()) {
+ // Subtracting from a null pointer should produce a warning.
+ // The last argument to the diagnose call says this doesn't match the
----------------
rsmith wrote:
> Subtracting zero from a null pointer should not warn in C++.
>
> (Conversely, subtracting a non-null pointer from a pointer should warn in C++, and subtracting any pointer from a null pointer should warn in C.)
Is it OK if I just add a FIXME in the section below that handles pointer-pointer?
https://reviews.llvm.org/D37042
More information about the cfe-commits
mailing list