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