view gcc/testsuite/g++.dg/expr/ptr-comp1.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
line wrap: on
line source

// DR 1512
// PR c++/87699
// { dg-do compile { target c++11 } }

/* Relational comparisons between null pointer constants and pointers are now
   ill-formed.  */

void
f (char *p)
{
  if (p > 0) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p >= 0) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p < 0) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p <= 0) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p > nullptr) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p >= nullptr) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p < nullptr) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (p <= nullptr) { } // { dg-error "ordered comparison of pointer with integer zero" }
}

void
f2 (char *p)
{
  if (0 > p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (0 >= p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (0 < p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (0 <= p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (nullptr > p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (nullptr >= p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (nullptr < p) { } // { dg-error "ordered comparison of pointer with integer zero" }
  if (nullptr <= p) { } // { dg-error "ordered comparison of pointer with integer zero" }
}