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

            Bug ID: 90971
           Summary: Suboptimal diagnostic for is_same_v requirement for
                    std::array
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: b7.10110111 at gmail dot com
  Target Milestone: ---

Consider the following code:


```
#include <array>

int main()
{
    std::array arr={1.32,5,45.3463,4.674,-94.463,34.634};
}
```


GCC 9.1 (9.1.0-2ubuntu2~18.04) gives the following diagnostic with -std=c++17
option:


```
test.cpp: In function ‘int main()’:
test.cpp:5:53: error: class template argument deduction failed:
    5 |  std::array arr={1.32,5,45.3463,4.674,-94.463,34.634};
      |                                                     ^
test.cpp:5:53: error: no matching function for call to ‘array(double, int,
double, double, double, double)’
In file included from test.cpp:1:
/usr/include/c++/9/array:244:5: note: candidate: ‘template<class _Tp, class ...
_Up> std::array(_Tp, _Up ...)-> std::array<typename
std::enable_if<(is_same_v<_Tp, _Up> && ...), _Tp>::type, (1 + sizeof...
(_Up))>’
  244 |     array(_Tp, _Up...)
      |     ^~~~~
/usr/include/c++/9/array:244:5: note:   template argument
deduction/substitution failed:
/usr/include/c++/9/array: In substitution of ‘template<class _Tp, class ...
_Up> std::array(_Tp, _Up ...)-> std::array<typename
std::enable_if<(is_same_v<_Tp, _Up> && ...), _Tp>::type, (1 + sizeof... (_Up))>
[with _Tp = double; _Up = {int, double, double, double, double}]’:
test.cpp:5:53:   required from here
/usr/include/c++/9/array:244:5: error: no type named ‘type’ in ‘struct
std::enable_if<false, double>’
```


This error message "error: no type named ‘type’ in ‘struct
std::enable_if<false, double>’" is not too useful. Yes, it is technically
correct, but compare it to what clang 6.0 (6.0.0-1ubuntu2) prints instead:


```
test.cpp:5:13: error: no viable constructor or deduction guide for deduction of
template arguments of 'array'
        std::array arr={1.32,5,45.3463,4.674,-94.463,34.634};
                   ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/array:244:5:
note: candidate template ignored: requirement 'is_same_v<double, int>' was not
satisfied [with _Tp = double,
      _Up = <int, double, double, double, double>]
    array(_Tp, _Up...)
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/array:94:12:
note: candidate function template not viable: requires 0 arguments, but 6 were
provided
    struct array
           ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/array:94:12:
note: candidate function template not viable: requires 1 argument, but 6 were
provided
1 error generated.
```


Note this: "requirement 'is_same_v<double, int>' was not satisfied". It's much
better than what GCC says.

Reply via email to