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

--- Comment #1 from Tom Honermann <tom at honermann dot net> ---
Created attachment 38876
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38876&action=edit
Patch to elucidate failed constraints

The attached patch was provided to me by Andrew Sutton earlier this year and
applies cleanly to gcc 6 trunk (r238201).

The patch modifies the error messages emitted for constraint satisfaction
failures so that the specific constraints that were not satisfied will be
listed, up to a maximum of 7 constraints for each overload candidate.

Ideally, the number of constraints to list would be controlled by command line
options, but the patch does not currently provide such control.

Example diagnostics provided by this patch:

$ cat t.cpp
template<typename T>
concept bool C = requires(T t) {
    typename T::type;
    t.i;
    t.i2;
    t.i3;
    t.i4;
    t.i5;
    t.i6;
    t.i7;
    t.i8;
};
template<C T>
auto f(T t) {
    return t.i;
}
struct S {
};
auto x = f(S{});

$ g++ -c -std=c++1z -fconcepts t.cpp
t.cpp:19:15: error: cannot call function ‘auto f(T) [with T = S]’
 auto x = f(S{});
               ^
t.cpp:14:6: note:   constraints not satisfied
 auto f(T t) {
      ^
t.cpp:14:6: note:   concept ‘C<S>’ was not satisfied
t.cpp:2:14: note: within the concept template<class T> constexpr const bool
C<T> [with T = S]
 concept bool C = requires(T t) {
              ^
t.cpp:2:14: note:   the required type ‘typename T::type’ would be ill-formed
t.cpp:2:14: note:   the required expression ‘t.i’ would be ill-formed
t.cpp:2:14: note:   the required expression ‘t.i2’ would be ill-formed
t.cpp:2:14: note:   the required expression ‘t.i3’ would be ill-formed
t.cpp:2:14: note:   the required expression ‘t.i4’ would be ill-formed
t.cpp:2:14: note:   the required expression ‘t.i5’ would be ill-formed
t.cpp:14:6: note: ... 2 constraint errors not shown
 auto f(T t) {
      ^

This patch does not affect the diagnostics produced for failed static
assertions of constraint satisfaction.  Ideally, those diagnostics would be
improved to list specific constraints as well.

Reply via email to