C – Free deduction guide taken by Clang – Who is correct?

Please consider the following code:

template 
struct list
{
template
list(Args...)
{
static_assert(sizeof...(Types)> 0);
}
};

template
list(Args...) -> list;
< br />int main()
{
list l{0, 0.1,'a'};
}

I hope decltype(l) is list< int ,double,char>. Unfortunately, g 7.2 and g trunk failed the static assertion. clang 5.0.0 and clang trunk compile and work as expected.

godbolt.org conformance view

Is this a g bug? Or, why shouldn’t deduction guidelines be followed?

Adding the SFINAE constraint on the constructor seems to provide the desired behavior:

template  typename = std::enable_if_t>
list(Args...)
{
static_assert(sizeof...( Types)> 0);
}

godbolt.org conformance view

This is gcc bug 80871. The problem is that we finally got this set of candidates for deduction:

template 
list __f(Args... ); // constructor

template < br />list __f(Args... ); // deduction-guide

Both are valid (type… can be inferred to be empty in the first case ), but the call here should be vague-neither is more professional than the other. Type… does not participate in the ordering here (similar to the example in [temp.deduct.partial]/12). Therefore, the correct behavior is Enter the next decisive game, that is, favorites deduction-guides. Therefore, this should be a list .

However, the behavior of gcc is to support constructors, so the static_assert trigger is because of the type …It is indeed empty in that case.

Please consider the following code:

template 
struct list
{
template
list(Args...)
{
static_assert(sizeof...(Types)> 0);
}
};

template < typename... Args>
list(Args...) -> list;

int main()
{
list l {0, 0.1,'a'};
}

I want decltype(l) to be list. Unfortunately, g 7.2 and g trunk failed statically Assertion. clang 5.0.0 and clang trunk compile and work as expected.

godbolt.org conformance view

Is this a g bug? Or, why shouldn’t deduction guidelines be followed?

Adding the SFINAE constraint on the constructor seems to provide the desired behavior:

template  typename = std::enable_if_t>
list(Args...)
{
static_assert(sizeof...( Types)> 0);
}

godbolt.org conformance view

This is gcc bug 80871. The problem is that we finally got this set of candidates for deduction:

template < br />list __f(Args... ); // constructor

template
list __f( Args... ); // deduction-guide

Both are valid (type… can be inferred to be empty in the first case), but the call here should be ambiguous-both No more professional than the other. Type…do not participate in the ordering here (similar to the example in [temp.deduct.partial]/12). Therefore, the correct behavior is to enter the next tiebreaker, which is the favorites deduction-guides. Therefore, this should be a list .

However, gcc’s behavior is to support constructors, so the static_assert trigger is really empty because of the type… in that case.

Leave a Comment

Your email address will not be published.