OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.dg/] [warn/] [null4.C] - Blame information for rev 328

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 301 jeremybenn
// PR c++/24745 : warnings for NULL constant.
2
// { dg-do compile  }
3
// { dg-options "-Wpointer-arith -Wconversion " }
4
 
5
#include 
6
 
7
int foo (void)
8
{
9
  if (NULL == 1) return -1;   // { dg-warning "NULL used in arithmetic" }
10
  if (NULL > NULL) return -1; // { dg-warning "NULL used in arithmetic" }
11
  if (NULL < NULL) return -1; // { dg-warning "NULL used in arithmetic" }
12
  if (NULL >= 0) return -1;   // { dg-warning "NULL used in arithmetic" }
13
  if (NULL <= 0) return -1;   // { dg-warning "NULL used in arithmetic" }
14
  // Adding to the NULL pointer, which has no specific type, should
15
  // result in a warning; the type of the resulting expression is
16
  // actually "int", not a pointer type.
17
  if (NULL + 1) return -1;    // { dg-warning "NULL used in arithmetic" }
18
  if (1 + NULL) return -1;    // { dg-warning "NULL used in arithmetic" }
19
  return 0;
20
}
21
 
22
int *ip;
23
 
24
struct S {};
25
typedef int S::*SPD;
26
typedef void (S::*SPF)(void);
27
SPD spd;
28
SPF spf;
29
 
30
int bar (void)
31
{
32
  if (NULL) return -1;
33
  if (!NULL) return -1;
34
  if (!NULL == 1) return -1;
35
  if (NULL || NULL) return -1;
36
  if (!NULL && NULL) return -1;
37
  if (NULL == NULL) return -1;
38
  if (NULL != NULL) return -1;
39
  if (NULL == 0) return -1;
40
  if (NULL != 0) return -1;
41
  // Subtraction of pointers is vaild, so using NULL is OK.
42
  if (ip - NULL) return -1;
43
  if (NULL - NULL) return -1;
44
  // Comparing NULL with a pointer-to-member is OK.
45
  if (NULL == spd) return -1;
46
  if (spd == NULL) return -1;
47
  if (NULL != spd) return -1;
48
  if (spd != NULL) return -1;
49
  if (NULL == spf) return -1;
50
  if (spf == NULL) return -1;
51
  if (NULL != spf) return -1;
52
  if (spf != NULL) return -1;
53
 
54
  return 0;
55
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.