(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
c2x-auto-3.c
       1  /* Test C2x auto.  Invalid code.  */
       2  /* { dg-do compile } */
       3  /* { dg-options "-std=c2x -pedantic-errors" } */
       4  
       5  auto; /* { dg-error "empty declaration" } */
       6  auto *p = (int *) 0; /* { dg-error "plain identifier" } */
       7  auto i; /* { dg-error "initialized data declaration" } */
       8  auto g { } /* { dg-error "initialized data declaration" } */
       9  auto a = 1, b = 2; /* { dg-error "single declarator" } */
      10  auto long e0 = 0; /* { dg-error "file-scope declaration" } */
      11  long auto e1 = 0; /* { dg-error "file-scope declaration" } */
      12  int auto e2 = 0; /* { dg-error "file-scope declaration" } */
      13  
      14  extern int e3;
      15  auto e3 = 1; /* { dg-error "underspecified declaration of 'e3', which is already declared in this scope" } */
      16  
      17  void
      18  f ()
      19  {
      20    extern int fe1;
      21    auto fe1 = 1; /* { dg-error "underspecified declaration of 'fe1', which is already declared in this scope" } */
      22    /* { dg-error "declaration of 'fe1' with no linkage follows extern declaration" "linkage error" { target *-*-* } .-1 } */
      23    auto fe2 = (struct s *) 0; /* { dg-error "declared in underspecified object initializer" } */
      24    auto fe3 = (union u *) 0; /* { dg-error "declared in underspecified object initializer" } */
      25    auto fe4 = (struct s2 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      26    auto fe5 = (struct { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      27    auto fe6 = (union u2 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      28    auto fe7 = (union { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      29    auto fe8 = sizeof (enum e { A }); /* { dg-error "defined in underspecified object initializer" } */
      30    /* The following case is undefined behavior (so doesn't actually require a
      31       diagnostic).  */
      32    auto fe9 = sizeof (enum { B }); /* { dg-error "defined in underspecified object initializer" } */
      33    /* Examples with a forward declaration, then definition inside auto.  */
      34    struct s3;
      35    auto fe10 = (struct s3 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      36    union u3;
      37    auto fe11 = (union u3 { int a; }) { }; /* { dg-error "defined in underspecified object initializer" } */
      38  }
      39  
      40  void f2 (auto x); /* { dg-error "storage class specified for parameter" } */
      41  void f3 (auto y) { } /* { dg-error "storage class specified for parameter" } */
      42  
      43  auto e4 = sizeof (e4); /* { dg-error "underspecified 'e4' referenced in its initializer" } */
      44  __SIZE_TYPE__ e5;
      45  void
      46  f4 ()
      47  {
      48    auto e5 = sizeof (e5); /* { dg-error "underspecified 'e5' referenced in its initializer" } */
      49  }
      50  
      51  auto typedef int T; /* { dg-error "'typedef' used with 'auto'" } */
      52  auto auto e6 = 1; /* { dg-error "duplicate 'auto'" } */
      53  static auto int e7 = 1; /* { dg-error "multiple storage classes in declaration specifiers" } */
      54  _Thread_local auto int e8 = 2; /* { dg-error "'_Thread_local' used with 'auto'" } */
      55  _Thread_local int auto e9 = 3; /* { dg-error "'_Thread_local' used with 'auto'" } */
      56  /* { dg-error "file-scope declaration of 'e9' specifies 'auto'" "file-scope error" { target *-*-* } .-1 } */
      57  
      58  typedef auto int T2; /* { dg-error "multiple storage classes in declaration specifiers" } */
      59  
      60  void
      61  f5 ()
      62  {
      63    static int auto e10 = 3; /* { dg-error "multiple storage classes in declaration specifiers" } */
      64  }
      65  
      66  void
      67  f6 ()
      68  {
      69    static auto l = { 0L }; /* { dg-error "expected expression" } */
      70    const auto i3 [[]] = { 4, }; /* { dg-error "expected expression" } */
      71  }