aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/nonnull-1.c
blob: fb2814c44981cfbccc74fb926f61aabb6b92f8e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* Test for the bad usage of "nonnull" function attribute parms.  */
/*  */
/* { dg-do compile } */
/* { dg-options "-Wnonnull-compare" } */

#include <stddef.h>
#include <stdlib.h>

void foo(void *bar) __attribute__((nonnull(1)));

void foo(void *bar) { if (!bar) abort(); } /* { dg-warning "nonnull argument" "bar compared to NULL" } */

extern int func (char *, char *, char *, char *) __attribute__((nonnull));

int
func (char *cp1, char *cp2, char *cp3, char *cp4)
{
  if (cp1) /* { dg-warning "nonnull argument" "cp1 compared to NULL" } */
    return 1;

  if (cp2 == NULL) /* { dg-warning "nonnull argument" "cp2 compared to NULL" } */
    return 2;

  if (NULL != cp3) /* { dg-warning "nonnull argument" "cp3 compared to NULL" } */
    return 3;

  return (cp4 != 0) ? 0 : 1; /* { dg-warning "nonnull argument" "cp4 compared to NULL" } */
}