[Bug c++/52964] New: No warning on negative array size in template instantatiation

xinliangli at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Apr 12 22:15:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52964

             Bug #: 52964
           Summary: No warning on negative array size in template
                    instantatiation
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: xinliangli@gmail.com


template <int N> struct S1 { int arr[N - 5]; };
template <typename T> struct S2 { S1<sizeof(T)> s1; };
template <typename T> void foo(T x) { S2<T> s2; }
void test() { foo(42); }

/* From Clang:
templates1.cpp:1:38: error: 'arr' declared as an array with a negative
size
template <int N> struct S1 { int arr[N - 5]; };
                                    ^~~~~
templates1.cpp:2:49: note: in instantiation of template class 'S1<4>'
requested here
template <typename T> struct S2 { S1<sizeof(T)> s1; };
                                               ^
templates1.cpp:3:45: note: in instantiation of template class 'S2<int>'
requested here
template <typename T> void foo(T x) { S2<T> s2; }
                                           ^
templates1.cpp:4:15: note: in instantiation of function template
specialization 'foo<int>' requested here
void test() { foo(42); }
==============================================     */



More information about the Gcc-bugs mailing list