This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/66834] [concepts] concept parameter kind mismatch causes hard error
- From: "eric.niebler at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 11 Jul 2015 17:29:09 +0000
- Subject: [Bug c++/66834] [concepts] concept parameter kind mismatch causes hard error
- Auto-submitted: auto-generated
- References: <bug-66834-4 at http dot gcc dot gnu dot org/bugzilla/>
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?