On 06/25/2012 05:25 AM, Jason Merrill wrote: > On 06/11/2012 12:11 PM, Florian Weimer wrote: >> + tree inner_nelts_cst = maybe_constant_value (inner_nelts); >> + if (!TREE_CONSTANT (inner_nelts_cst)) >> + { >> + if (complain & tf_error) >> + error_at (EXPR_LOC_OR_HERE (inner_nelts), >> + "array size in operator new must be constant"); > > Please use cxx_constant_value to give a more specific error about what > is non-constant. Thanks for your review. I tried this, but for this example program, /* 1 */ void f(int n, int m) /* 2 */ { /* 3 */ typedef char T[n]; /* 4 */ new T[m]; /* 5 */ } GCC reports these errors: /tmp/t.C: In function ‘void f(int, int)’: /tmp/t.C:4:18: error: array size in operator new must be constant /* 4 */ new T[m]; ^ /tmp/t.C:4:18: error: ‘n’ is not a constant expression The message should point to the typedef, but instead, it references the line with operator new (which doesn't even contain the variable n). For the non-VLA typedef case, it is an improvement. But I would like to leave in both errors, as in the attached patch. If you have suggestions how to improve cxx_constant_value error reporting, I can look into that in a separate patch. >> + /* Warn if we performed the (T[N]) to T[N] transformation and N is >> + variable. */ >> + if (outer_nelts_from_type >> + && !TREE_CONSTANT (maybe_constant_value (outer_nelts)) >> + && (complain & tf_warning_or_error)) >> + pedwarn(EXPR_LOC_OR_HERE (outer_nelts), OPT_Wvla, >> + "ISO C++ does not support variable-length array types"); > > Here, if we aren't complaining we should return error_mark_node; we > always need to act pedantic in SFINAE context. The new version should do that. I've added a new test case about error reporting in templates (where we previously accepted ill-formed code such as new long[n][T::n] with n, T::n both variables). Bootstrapped and tested on x86_64-unknown-linux-gnu, with no new regressions. OK for trunk? -- Florian Weimer / Red Hat Product Security Team