(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
c2x-qual-4.c
       1  /* { dg-do compile } */
       2  /* { dg-options "-std=c2x" } */
       3  void tvoid(void* x);
       4  void transpose0(double* out, const double* in) { }
       5  void transpose1(double out[2][2], const double in[2][2]) { }
       6  void transpose2(double out[2][2][2], const double in[2][2][2]) { }
       7  // return
       8  int (*y2(const int x[3][3]))[3] { return x; } /* { dg-warning "return discards 'const' qualifier from pointer target type" } */
       9  const int (*y3(int x[3][3]))[3] { return x; }
      10  void test(void)
      11  {
      12  	double x0[2];
      13  	double y0[2];
      14  	const double z0[4];
      15  	double x1[2][2];
      16  	double y1[2][2];
      17  	double o1[2][3];
      18  	const double z1[2][2];
      19  	double x2[2][2][2];
      20  	double y2[2][2][2];
      21  	double o2[2][2][3];
      22  	const double z2[2][2][2];
      23  	// void pointers
      24  	tvoid(x0);
      25  	tvoid(x1);
      26  	tvoid(x2);
      27  	tvoid(z0); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
      28  	tvoid(z1); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
      29  	tvoid(z2); /* { dg-warning "passing argument 1 of 'tvoid' discards 'const' qualifier from pointer target type" } */
      30  	void* p;
      31  	const void* pc;
      32  	p = x0;
      33  	p = x1;
      34  	p = x2;
      35  	p = z0; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      36  	p = z1; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      37  	p = z2; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      38  	pc = x0;
      39  	pc = x1;
      40  	pc = x2;
      41  	pc = z0;
      42  	pc = z1;
      43  	pc = z2;
      44  	transpose0(pc, p); /* { dg-warning "passing argument 1 of 'transpose0' discards 'const' qualifier from pointer target type" } */
      45  	transpose1(pc, p); /* { dg-warning "passing argument 1 of 'transpose1' discards 'const' qualifier from pointer target type" } */
      46  	transpose2(pc, p); /* { dg-warning "passing argument 1 of 'transpose2' discards 'const' qualifier from pointer target type" } */
      47  	transpose0(p, pc);
      48  	transpose1(p, pc);
      49  	transpose2(p, pc);
      50  	// passing as arguments
      51  	transpose0(y0, x0);
      52  	transpose1(y1, x1);
      53  	transpose2(y2, x2);
      54  	// initialization
      55  	const double (*u0p) = x0;
      56  	const double (*u1p)[2] = x1;
      57  	const double (*u2p)[2][2] = x2;
      58  	double (*v0p) = z0; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
      59  	double (*v1p)[2] = z1; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
      60  	double (*v2p)[2][2] = z2; /* { dg-warning "initialization discards 'const' qualifier from pointer target type" } */
      61  	// subtraction
      62  	&(x0[1]) - &(z0[0]);
      63  	&(x1[1]) - &(z1[0]);
      64  	&(x2[1]) - &(z2[0]);
      65  	// comparison
      66  	x0 == z0;
      67  	x1 == z1;
      68  	x2 == z2;
      69  	x0 < z0; 
      70  	x1 < z1; 
      71  	x2 < z2; 
      72  	x0 > z0;
      73  	x1 > z1;
      74  	x2 > z2;
      75  	// assignment
      76  	u0p = x0;
      77  	u1p = x1;
      78  	u2p = x2;
      79  	v0p = z0; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      80  	v1p = z1; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      81  	v2p = z2; /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      82  	// conditional expressions
      83  	(void)(1 ? x0 : z0);
      84  	(void)(1 ? x1 : z1);
      85  	(void)(1 ? x2 : z2);
      86  	(void)(1 ? x0 : x1); /* { dg-warning "pointer type mismatch in conditional expression" } */
      87  	(void)(1 ? x1 : x2); /* { dg-warning "pointer type mismatch in conditional expression" } */
      88  	(void)(1 ? x2 : x0); /* { dg-warning "pointer type mismatch in conditional expression" } */
      89  	v0p = (1 ? z0 : v0p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      90  	v1p = (1 ? z1 : v1p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      91  	v2p = (1 ? z2 : v2p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      92  	v0p = (1 ? x0 : u0p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      93  	v1p = (1 ? x1 : u1p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      94  	v2p = (1 ? x2 : u2p); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      95  	(1 ? x0 : z0)[0] = 1; /* { dg-error "assignment of read-only location" } */
      96  	(1 ? x1 : z1)[0][0] = 1; /* { dg-error "assignment of read-only location" } */
      97  	(1 ? x2 : z2)[0][0][0] = 1; /* { dg-error "assignment of read-only location" } */
      98  	v0p = (1 ? p : z0); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
      99  	v1p = (1 ? p : z1); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
     100  	v2p = (1 ? p : z2); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
     101  	v0p = (1 ? pc : x0); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
     102  	v1p = (1 ? pc : x1); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
     103  	v2p = (1 ? pc : x2); /* { dg-warning "assignment discards 'const' qualifier from pointer target type" } */
     104  }
     105