This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/68280] New: dependent arrays of excessive size not diagnosed


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

            Bug ID: 68280
           Summary: dependent arrays of excessive size not diagnosed
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Similar to bug 68266, except in type-dependent expressions, arrays of excessive
size are accepted, leading to overflow/wrapping in sizeof expressions involving
such types.  Since bug 68266 is about pointers and affects both C and C++ while
this one is C++ specific and will likely require changes in different places, I
raise this as a separate issue.

$ cat u.cpp && g++ -Wall -Wextra u.cpp && ./a.out 
#include <assert.h>

typedef __typeof__ (sizeof 0) size_t;

template <class T, size_t N> 
void foo () {
    const size_t array_size = sizeof (T[N]);
    assert (array_size / sizeof (T) == N); 
}

int main ()
{
    foo<int, __SIZE_MAX__>();
}
a.out: u.cpp:8: void foo() [with T = int; long unsigned int N =
18446744073709551615ul]: Assertion `array_size / sizeof (T) == N' failed.
Aborted (core dumped)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]