view gcc/testsuite/g++.dg/cpp0x/range-for5.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
line wrap: on
line source

// Test for errors in range-based for loops

// { dg-do compile { target c++11 } }

struct container
{
};

int *begin(const container &c)
{
  return 0;
}

int end(const container &c) //Ops! wrong type
{
  return 0;
}


struct Implicit
{
  Implicit(int x)
  {}
};
struct Explicit
{
  explicit Explicit(int x)
  {}
};

void test1()
{
  container c;
  for (int x : c) // { dg-error "inconsistent|conversion|comparison" }
    ;

  int a[2] = {1,2};
  for (Implicit x : a)
    ;
  for (Explicit x : a) // { dg-error "conversion" }
    ;
  for (const Implicit &x : a)
    ;
  for (Implicit &&x : a)
    ;

  //Check the correct scopes
  int i;
  for (int i : a)		// { dg-message "previously declared" }
  {
    int i;			// { dg-error "redeclaration" }
  }
}