view gcc/testsuite/c-c++-common/nonnull-2.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 1830386684a0
line wrap: on
line source

/* Test for the bad usage of "nonnull" function attribute parms.  */
/* { dg-do compile } */
/* { dg-options "-Wnonnull-compare" } */

void bar (char **);

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

  cp1 = cp2;
  if (cp1 == (char *) 0) /* { dg-bogus "nonnull argument" } */
    return 2;

  if (!cp4)	   /* { dg-bogus "nonnull argument" } */
    return 3;

  char **p = &cp3;
  bar (p);
  if (cp3 == (char *) 0) /* { dg-bogus "nonnull argument" } */
    return 4;

  return 5;
}