view gcc/testsuite/g++.dg/concepts/expression2.C @ 131:84e7813d76e9

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

// { dg-do compile { target c++17 } }
// { dg-options "-fconcepts" }

template<typename T>
concept bool C1()
{
  return requires (T t) { t.f(); };
}

template<typename T>
concept bool C2()
{
  return requires { typename T::type; };
}

template<typename T>
  requires C1<T>()
void f1(T x) { }

template<typename T>
  requires C2<T>()
void f2(T x) { }

// Note that these declarations are private and therefore
// cannot satisify the constraints.
class S
{
  using type = int;
  void f() { }
} s;

int main()
{
  f1(s); // { dg-error "cannot call" }
  f2(s); // { dg-error "" }

  // When used in non-SFINAE contexts, make sure that we fail
  // the constraint check before emitting the access check
  // failures. The context is being presented constistently
  // in both cases.
  static_assert(C1<S>(), ""); // { dg-error "failed" }
  static_assert(C2<S>(), ""); // { dg-error "" }
}