public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96286] New: Unhelpful errors after a failed static_assert
@ 2020-07-22 15:00 redi at gcc dot gnu.org
  2021-07-15 10:44 ` [Bug c++/96286] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2020-07-22 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96286
           Summary: Unhelpful errors after a failed static_assert
           Product: gcc
           Version: 10.1.1
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

template<typename T>
struct S
{
  static_assert( sizeof(T) < 4, "smol" );

  char* p = new char[3 - sizeof(T)];
};

S<long long> s;


GCC gives two errors:

sa.C: In instantiation of ‘struct S<long long int>’:
sa.C:9:14:   required from here
sa.C:4:28: error: static assertion failed: smol
    4 |   static_assert( sizeof(T) < 4, "smol" );
      |                  ~~~~~~~~~~^~~
sa.C: In instantiation of ‘constexpr S<long long int>::S()’:
sa.C:9:14:   required from here
sa.C:6:24: error: size ‘18446744073709551611’ of array exceeds maximum object
size ‘9223372036854775807’
    6 |   char* p = new char[3 - sizeof(T)];
      |                      ~~^~~~~~~~~~~

The second error is unhelpful. I know the array size is invalid, that's why I
put the static assertion there.

Clang just says:

sa.C:4:3: error: static_assert failed due to requirement 'sizeof(long long) <
4' "smol"
  static_assert( sizeof(T) < 4, "smol" );
  ^              ~~~~~~~~~~~~~
sa.C:9:14: note: in instantiation of template class 'S<long long>' requested
here
S<long long> s;
             ^
1 error generated.

EDG says:

"sa.C", line 4: error: static assertion failed with "smol"
    static_assert( sizeof(T) < 4, "smol" );
    ^
          detected during instantiation of class "S<T> [with T=long long]" at
                    line 9

1 error detected in the compilation of "sa.C".

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

end of thread, other threads:[~2021-09-02 12:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-22 15:00 [Bug c++/96286] New: Unhelpful errors after a failed static_assert redi at gcc dot gnu.org
2021-07-15 10:44 ` [Bug c++/96286] " redi at gcc dot gnu.org
2021-07-15 10:56 ` redi at gcc dot gnu.org
2021-07-15 11:21 ` redi at gcc dot gnu.org
2021-08-30 21:27 ` cvs-commit at gcc dot gnu.org
2021-08-31 21:48 ` jason at gcc dot gnu.org
2021-09-02 12:27 ` jason at gcc dot gnu.org
2021-09-02 12:27 ` jason at gcc dot gnu.org
2021-09-02 12:56 ` redi 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).