if (IsPointerAttr) {
// Skip implicit cast of pointer to `void *' (as a function argument).
if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(ArgumentExpr))
- if (ICE->getType()->isVoidPointerType())
+ if (ICE->getType()->isVoidPointerType() &&
+ ICE->getCastKind() != CK_NullToPointer &&
+ ICE->getCastKind() != CK_NullToMemberPointer)
ArgumentExpr = ICE->getSubExpr();
}
QualType ArgumentType = ArgumentExpr->getType();
// Layout-compatible scalar types.
MPI_Send(int_buf, 1, MPI_INT); // no-warning
+ // Null pointer constant.
+ MPI_Send(0, 0, MPI_INT); // no-warning
+ MPI_Send(NULL, 0, MPI_INT); // no-warning
+
// Layout-compatible class types.
MPI_Send(pfi, 1, MPI_FLOAT_INT); // no-warning
MPI_Send(pii, 1, MPI_2INT); // no-warning
C_func(ptr, 20); // should warn, but may cause false positives
}
+void test_null_pointer()
+{
+ C_func(0, C_tag); // no-warning
+ C_func((void *) 0, C_tag); // no-warning
+ C_func((int *) 0, C_tag); // no-warning
+ C_func((long *) 0, C_tag); // expected-warning {{argument type 'long *' doesn't match specified 'c' type tag that requires 'int *'}}
+}
+
// Check that we look through typedefs in the special case of allowing 'char'
// to be matched with 'signed char' or 'unsigned char'.
void E_func(void *ptr, int tag) __attribute__(( pointer_with_type_tag(e,1,2) ));
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
typedef struct ompi_datatype_t *MPI_Datatype;
{
c->MPI_Send(int_buf, 1, MPI_INT); // no-warning
c->MPI_Send(int_buf, 1, MPI_FLOAT); // expected-warning {{argument type 'int *' doesn't match specified 'mpi' type tag that requires 'float *'}}
+ c->MPI_Send(0, 0, MPI_INT); // no-warning
+ c->MPI_Send(nullptr, 0, MPI_INT); // no-warning
OperatorIntStar i;
c->MPI_Send(i, 1, MPI_INT); // no-warning