[Bug c++/82893] New: Bad diagnostic on negative sized array
barry.revzin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 7 22:03:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82893
Bug ID: 82893
Summary: Bad diagnostic on negative sized array
Product: gcc
Version: 8.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 this example:
struct Foo {
int n;
};
struct Bar {
double n;
bool b;
};
template <typename T>
struct Baz : public T {
char pad[8 - sizeof(T)];
};
int main() {
static_assert(sizeof(Baz<Foo>) == 8, "");
static_assert(sizeof(Baz<Bar>) == 8, "");
}
The diagnostic that every gcc yields (on basically every version) is:
prog.cc:15:5: error: non-constant condition for static assertion
static_assert(sizeof(Baz<Bar>) == 8, "");
^~~~~~~~~~~~~
This is very misleading and unhelpful. It'd be nice if it were possible to get
a better diagnostic that points to the cause of the problem. clang, for
instance, yields:
prog.cc:10:14: error: array is too large (18446744073709551608 elements)
char pad[8 - sizeof(T)];
^~~~~~~~~~~~~
prog.cc:15:19: note: in instantiation of template class 'Baz<Bar>' requested
here
static_assert(sizeof(Baz<Bar>) == 8, "");
^
More information about the Gcc-bugs
mailing list