public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97518] New: Improving static_assert diagnostics
@ 2020-10-21 14:57 barry.revzin at gmail dot com
  2020-10-21 15:01 ` [Bug c++/97518] " mpolacek at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: barry.revzin at gmail dot com @ 2020-10-21 14:57 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-11-11 17:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-21 14:57 [Bug c++/97518] New: Improving static_assert diagnostics barry.revzin at gmail dot com
2020-10-21 15:01 ` [Bug c++/97518] " mpolacek at gcc dot gnu.org
2020-10-21 15:30 ` redi at gcc dot gnu.org
2020-11-06 19:29 ` mpolacek at gcc dot gnu.org
2020-11-10 20:08 ` cvs-commit at gcc dot gnu.org
2020-11-10 20:09 ` mpolacek at gcc dot gnu.org
2020-11-11 17:37 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).