This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61806] [C++11] Expression sfinae w/o access gives hard error in partial template specializations
- From: "gcc-bugs at marehr dot dialup.fu-berlin.de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 25 Sep 2017 13:52:16 +0000
- Subject: [Bug c++/61806] [C++11] Expression sfinae w/o access gives hard error in partial template specializations
- Auto-submitted: auto-generated
- References: <bug-61806-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61806
gcc-bugs at marehr dot dialup.fu-berlin.de changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gcc-bugs at marehr dot dialup.fu-b
| |erlin.de
--- Comment #3 from gcc-bugs at marehr dot dialup.fu-berlin.de ---
I think I encountered a variant of this bug.
Using this new awesome -fconcept feature, you can do the following:
```
template <typename type_t>
struct type_trait;
template <>
struct type_trait<int>
{
static constexpr auto length = 0;
};
template <>
struct type_trait<long>
{
private:
static constexpr auto length = 0;
};
template <typename type_t>
concept bool has_length = requires(type_t a)
{
{ type_trait<type_t>::length };
};
int main()
{
static_assert(!has_length<char>); // expect: false, has no ::length
static_assert(has_length<int>); // expect: true, has ::length
static_assert(!has_length<long>); // expect: false, ::length is non-visible
// but, last one fails in a compiler error
return 0;
}
```
This example asks whether a type_trait is defined for a given type. And it
would be super useful to be able to express this.
I think gcc uses internally SFINAE to check this but unfortunately fails
because of this bug (probably).