Exemple #1
0
void h()
{
    using B::f;
    using C::f;
    f('h');
    f(1);         // { dg-error "ambiguous" }
    // { dg-message "candidate" "candidate note" { target *-*-* } 22 }
    void f(int);  // { dg-error "previous using declaration" }
}
Exemple #2
0
void g()
{
    const B b;

    int *pi;
    pi = b.f(0);
}
Exemple #3
0
int main() {
  CHECK(fcc::invoke(f) == 13);
  CHECK(noexcept(fcc::invoke(f) == 13));
  CHECK(fcc::invoke(g, 2) == 5);
  CHECK(fcc::invoke(h, 42) == 42);
  CHECK(noexcept(fcc::invoke(h, 42) == 42));
  {
    int i = 13;
    CHECK(&fcc::invoke(h, i) == &i);
    CHECK(noexcept(&fcc::invoke(h, i) == &i));
  }

  CHECK(fcc::invoke(&A::f, A{}) == 42);
  CHECK(noexcept(fcc::invoke(&A::f, A{}) == 42));
  CHECK(fcc::invoke(&A::g, A{}, 2) == 4);
  {
    A a;
    const auto& ca = a;
    CHECK(fcc::invoke(&A::f, a) == 42);
    CHECK(noexcept(fcc::invoke(&A::f, a) == 42));
    CHECK(fcc::invoke(&A::f, ca) == 42);
    CHECK(noexcept(fcc::invoke(&A::f, ca) == 42));
    CHECK(fcc::invoke(&A::g, a, 2) == 4);
  }

  {
    A a;
    const auto& ca = a;
    CHECK(fcc::invoke(&A::f, &a) == 42);
    CHECK(noexcept(fcc::invoke(&A::f, &a) == 42));
    CHECK(fcc::invoke(&A::f, &ca) == 42);
    CHECK(noexcept(fcc::invoke(&A::f, &ca) == 42));
    CHECK(fcc::invoke(&A::g, &a, 2) == 4);
  }
  {
    auto up = std::make_unique<A>();
    CHECK(fcc::invoke(&A::f, up) == 42);
    CHECK(fcc::invoke(&A::g, up, 2) == 4);
  }
  {
    auto sp = std::make_shared<A>();
    CHECK(fcc::invoke(&A::f, sp) == 42);
    CHECK(noexcept(fcc::invoke(&A::f, sp) == 42));
    CHECK(fcc::invoke(&A::g, sp, 2) == 4);
  }

  CHECK(fcc::invoke(&A::i, A{}) == 13);
  CHECK(noexcept(fcc::invoke(&A::i, A{}) == 13));
  { int&& tmp = fcc::invoke(&A::i, A{}); (void)tmp; }

  {
    A a;
    const auto& ca = a;
    CHECK(fcc::invoke(&A::i, a) == 13);
    CHECK(noexcept(fcc::invoke(&A::i, a) == 13));
    CHECK(fcc::invoke(&A::i, ca) == 13);
    CHECK(noexcept(fcc::invoke(&A::i, ca) == 13));
    CHECK(fcc::invoke(&A::i, &a) == 13);
    CHECK(noexcept(fcc::invoke(&A::i, &a) == 13));
    CHECK(fcc::invoke(&A::i, &ca) == 13);
    CHECK(noexcept(fcc::invoke(&A::i, &ca) == 13));

    fcc::invoke(&A::i, a) = 0;
    CHECK(a.i == 0);
    fcc::invoke(&A::i, &a) = 1;
    CHECK(a.i == 1);
    static_assert(std::is_same<decltype(fcc::invoke(&A::i, ca)), const int&>{});
    static_assert(std::is_same<decltype(fcc::invoke(&A::i, &ca)), const int&>{});
  }

  {
    auto up = std::make_unique<A>();
    CHECK(fcc::invoke(&A::i, up) == 13);
    fcc::invoke(&A::i, up) = 0;
    CHECK(up->i == 0);
  }

  {
    auto sp = std::make_shared<A>();
    CHECK(fcc::invoke(&A::i, sp) == 13);
    fcc::invoke(&A::i, sp) = 0;
    CHECK(sp->i == 0);
  }
  
  {
    struct B { int i = 42; constexpr int f() const { return i; } };
    constexpr B b;
    static_assert(b.i == 42);
    static_assert(b.f() == 42);
    static_assert(fcc::invoke(&B::i, b) == 42);
    static_assert(fcc::invoke(&B::i, &b) == 42);
    static_assert(fcc::invoke(&B::i, B{}) == 42);
    static_assert(fcc::invoke(&B::f, b) == 42);
    static_assert(fcc::invoke(&B::f, &b) == 42);
    static_assert(fcc::invoke(&B::f, B{}) == 42);
  }

  return ::test_result();
}
void D::f(int) { f('c'); } // calls B::f(char)