This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/66834] [concepts] concept parameter kind mismatch causes hard error


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66834

--- Comment #3 from Eric Niebler <eric.niebler at gmail dot com> ---
I was thinking that overloading the Constructible concept would be a conforming
way to express this, but it doesn't seems to work. Any clue why?


template <class T, class U>
concept bool Same = __is_same_as(T, U);

template <class T, class U>
concept bool ExplicitlyConvertible() { return
  Same<T, U> ||
  requires(T&& t) {
    static_cast<U>((T&&)(t));
  };
}

template <class T, class... Args>
concept bool Constructible() { return
  ExplicitlyConvertible<Args..., T>() ||
  requires (Args&&... args) {
    T{ (Args&&)(args)... };
  };
}

template <class T, class U>
concept bool Constructible() { return
  ExplicitlyConvertible<U, T>() ||
  requires (U&& u) {
    T{ (U&&)(u) };
  };
}

template <class T, class U>
  requires Constructible<T, U>()
constexpr bool f() { return false; }

template <class T, ExplicitlyConvertible<T> >
constexpr bool f() { return true; }

static_assert(f<int,int>(), "");
static_assert(f<int,long>(), "");

struct A {
  A(int);
};
struct B {
  explicit B(int);
};
static_assert(f<A, int>(), "");
static_assert(!f<B, int>(), "");


Yields:

/cygdrive/c/Users/eric/Code/cmcstl2/test/core_concepts.cpp:32:25: error:
invalid reference to function concept âtemplate<class T, class U> constexpr
bool Constructible()â
   requires Constructible<T, U>()
                         ^
/cygdrive/c/Users/eric/Code/cmcstl2/test/core_concepts.cpp:48:1: error: static
assertion failed
 static_assert(!f<B, int>(), "");
 ^

I can't make sense of the error. Is this just a bug?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]