On Thu, Apr 23, 2009 at 5:39 PM, Joe Buck <joe.b...@synopsys.com> wrote: > > On Thu, Apr 23, 2009 at 1:38 PM, Denis Onischenko >> <denis.onische...@gmail.com> wrote: >> > The minimal code example is following: >> > >> > >> > extern unsigned int __invalid_size_argument; >> > #define TYPECHECK(t) ( sizeof(t) == sizeof(t[1]) ? sizeof(t) : >> > __invalid_size_argument ) >> > >> > static int arr[] = { >> > [TYPECHECK(int)] = 0, >> > }; >> > >> > int main() >> > { >> > return 0; >> > } >> > >> > >> > command line is: gcc test.c >> > >> > GCC 4.5.0 revision 146607 compiles this code with following errors: >> > test.c:5: error: nonconstant array index in initializer >> > test.c:5: error: (near initialization for 'arr') >> > >> > released GCC 4.4.0 compiles without any errors > > On Thu, Apr 23, 2009 at 04:58:17PM -0700, James Dennett wrote: >> A diagnostic is required in standards-conforming modes, as >> TYPECHECK(int) is not an "integral constant expression" (because it >> includes a non-constant in a potentially-evaluated operand). > > But there are cases where we avoid issuing such a diagnostic by > default, without flags such as -pedantic or calling out a specific > language standard. > > The compiler is not supposed to be pedantic by default. A standards > document saying that a diagnostic is required should not be the end > of the story, especially when we're talking about important, widely > used code bases.
Very true. Note that I explicitly refer only to "standards-conforming modes". Generating warnings for idiomatic use of system headers is not good for usability, though sometimes hard to avoid. -- James