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

            Bug ID: 97518
           Summary: Improving static_assert diagnostics
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider the following:

template <typename T, typename U> struct is_same { static constexpr bool value
= false; };
template <typename T> struct is_same<T, T> { static constexpr bool value =
true; };

template <typename T> using some_metafunction_t = T;

template <typename T>
void foo(T ) {
    using X = T*;
    using Y = some_metafunction_t<T>;

    static_assert(is_same<X, Y>::value);
}

void bar() {
    foo(0);
}

gcc emits:

<source>: In instantiation of 'void foo(T) [with T = int]':
<source>:15:10:   required from here
<source>:11:34: error: static assertion failed
   11 |     static_assert(is_same<X, Y>::value);
      |        

Notably, it does not tell me what either X or Y are. All I know is that they're
not the same. I get T, but the computation of X and Y could be fairly
complicated and T may not help (or even be relevant, necessarily). This ends up
being useless for me, to the point where I actually created my own verify_same
type such that verify_same<T, U> is only defined when T == U, and create a
variable like:

[[maybe_unused]] verify_same<T, U> _;

It would be a lot cooler if gcc could diagnose all the types and values that
were used in a static_assert condition. 

clang, for instance, gives me:

<source>:11:5: error: static_assert failed due to requirement 'is_same<int *,
int>::value'
    static_assert(is_same<X, Y>::value);
    ^             ~~~~~~~~~~~~~~~~~~~~
<source>:15:5: note: in instantiation of function template specialization
'foo<int>' requested here
    foo(0);
    ^

Which, while it doesn't tell me that X=int* and Y=int, at least clearly
illustrates both types, and is a much more useful error diagnostic.

Reply via email to