(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
c11-typedef-1.c
       1  /* Test typedef redeclaration in C11.  */
       2  /* { dg-do compile } */
       3  /* { dg-options "-std=c11 -pedantic-errors" } */
       4  
       5  /* C11 permits typedefs to be redeclared to the same type, but not to
       6     different-but-compatible types, and not when the type is variably
       7     modified.  */
       8  
       9  #include <limits.h>
      10  
      11  typedef int TI;
      12  typedef int TI2;
      13  typedef TI2 TI;
      14  typedef TI TI2;
      15  
      16  enum e { E1 = 0, E2 = INT_MAX, E3 = -1 };
      17  typedef enum e TE;
      18  typedef enum e TE; /* { dg-message "previous declaration" } */
      19  typedef int TE; /* { dg-error "with different type" } */
      20  
      21  struct s;
      22  typedef struct s TS;
      23  struct s { int i; };
      24  typedef struct s TS;
      25  
      26  typedef int IA[];
      27  typedef TI2 IA[]; /* { dg-message "previous declaration" } */
      28  typedef int A2[2];
      29  typedef TI A2[2]; /* { dg-message "previous declaration" } */
      30  typedef IA A2; /* { dg-error "with different type" } */
      31  typedef int A3[3];
      32  typedef A3 IA; /* { dg-error "with different type" } */
      33  
      34  typedef void F(int);
      35  typedef void F(TI); /* { dg-message "previous declaration" } */
      36  typedef void F(enum e); /* { dg-error "with different type" } */
      37  
      38  typedef int G(void);
      39  typedef TI G(void); /* { dg-message "previous declaration" } */
      40  typedef enum e G(void); /* { dg-error "with different type" } */
      41  
      42  typedef int *P;
      43  typedef TI *P; /* { dg-message "previous declaration" } */
      44  typedef enum e *P; /* { dg-error "with different type" } */
      45  
      46  typedef void F2();
      47  typedef void F2(); /* { dg-message "previous declaration" } */
      48  typedef void F2(int); /* { dg-error "with different type" } */
      49  
      50  void
      51  f (void)
      52  {
      53    int a = 1;
      54    int b = 2;
      55    typedef void FN(int (*p)[a]);
      56    typedef void FN(int (*p)[b]);
      57    typedef void FN(int (*p)[*]); /* { dg-message "previous declaration" } */
      58    typedef void FN(int (*p)[1]); /* { dg-error "with different type" } */
      59    typedef void FN2(int (*p)[a]);
      60    typedef void FN2(int (*p)[b]);
      61    typedef void FN2(int (*p)[*]); /* { dg-message "previous declaration" } */
      62    typedef void FN2(int (*p)[]); /* { dg-error "with different type" } */
      63    typedef int AV[a]; /* { dg-message "previous declaration" } */
      64    typedef int AV[b-1]; /* { dg-error "redefinition" } */
      65    typedef int AAa[a]; /* { dg-message "previous declaration" } */
      66    typedef int AAb[b-1];
      67    typedef AAa *VF(void); /* { dg-message "previous declaration" } */
      68    typedef AAb *VF(void); /* { dg-error "redefinition" } */
      69    typedef AAa AAa; /* { dg-error "redefinition" } */
      70  }