public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "barry.revzin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/97518] New: Improving static_assert diagnostics
Date: Wed, 21 Oct 2020 14:57:27 +0000	[thread overview]
Message-ID: <bug-97518-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2020-10-21 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21 14:57 barry.revzin at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97518-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).