1  /* Test C2x auto.  Valid code, compilation tests.  */
       2  /* { dg-do compile } */
       3  /* { dg-options "-std=c2x -pedantic-errors" } */
       4  
       5  auto i = 1;
       6  extern int i;
       7  static auto l = 0L;
       8  extern long l;
       9  extern auto const d = 0.0; /* { dg-warning "initialized and declared 'extern'" } */
      10  extern const double d;
      11  double dx;
      12  auto ((i2)) = 3;
      13  extern int i2;
      14  const auto i3 [[]] = 4;
      15  extern int i4;
      16  thread_local auto f = 1.0f;
      17  float ff;
      18  extern typeof (f) ff;
      19  auto h = (short) 0;
      20  extern short h;
      21  
      22  struct s { int a; };
      23  struct s sv;
      24  struct s2;
      25  enum e : int;
      26  
      27  extern const volatile long double cvld;
      28  extern void (*tfp) (void);
      29  
      30  int a[10];
      31  int *ap;
      32  
      33  typedef int ti;
      34  
      35  void
      36  tf ()
      37  {
      38    auto asv = (struct s) { 0 };
      39    extern typeof (asv) sv;
      40    auto s2p = (struct s2 *) 0;
      41    struct s3;
      42    auto s3p = (struct s3 *) 0;
      43    auto ev = (enum e) 0;
      44    static const auto volatile acvld = 0.5L;
      45    extern typeof (acvld) cvld;
      46    /* lvalue conversion occurs on the initializer, so losing qualifiers.  */
      47    auto ncd = d;
      48    extern typeof (ncd) dx;
      49    _Atomic double ad = 0.0;
      50    auto nad = ad;
      51    extern typeof (nad) dx;
      52    /* Function-to-pointer conversion occurs on the initializer.  */
      53    auto fp = tf;
      54    extern typeof (fp) tfp;
      55    /* Array-to-pointer conversion occurs on the initializer.  */
      56    auto aap = a;
      57    extern typeof (aap) ap;
      58    /* Shadowing a declaration from a containing scope is OK.  */
      59    auto i = 2L;
      60    extern typeof (i) l;
      61    /* auto can be used in for loops.  */
      62    for (auto ix = 2; ix < 10; ix++)
      63      {
      64        extern typeof (ix) i2;
      65      }
      66    /* auto is valid with bit-field initializers; the choice of type those have
      67       in expressions is unspecified but should match how _Generic handles such
      68       expressions.  */
      69    struct b { int a : 2; unsigned b : 3; } bv = { };
      70    auto bfa = bv.a;
      71    auto bfb = bv.b;
      72    static_assert (_Generic (bv.a, typeof (bfa) : 1, default : 2) == 1);
      73    static_assert (_Generic (bv.b, typeof (bfb) : 1, default : 2) == 1);
      74    /* The traditional meaning of auto with a type specifier is OK.  */
      75    auto short s;
      76    char auto c;
      77    auto struct t { int x; } t;
      78    /* That includes the case where the type comes from a typedef name.  */
      79    auto ti int_from_typedef = 3.0;
      80    extern typeof (int_from_typedef) i2;
      81  }