[cfe-commits] [Patch] Produce errors for 'static' and type qualifiers in array declarators
John McCall
rjmccall at apple.com
Sat Aug 11 12:14:02 PDT 2012
On Aug 10, 2012, at 2:27 AM, Hans Wennborg wrote:
> On Mon, Aug 6, 2012 at 7:47 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> + if (chunkIndex > 0) {
>> + const DeclaratorChunk &NextChunk = D.getTypeObject(chunkIndex - 1);
>> + if (NextChunk.Kind == DeclaratorChunk::Array) {
>>
>> This looks suspect: I think you need to trigger this error in more
>> cases. Consider, for example, "void f(int (*x)[static 10]);". Take a
>> look at checkQualifiedFunction.
>
> Ah, thanks for pointing that out. Attaching a new attempt.
+ unsigned x = chunkIndex;
+ for (;;) {
+ // Walk outwards along the declarator chunks.
+ if (x == 0)
+ break;
+ x--;
This can just be
while (x != 0) {
x--;
You could also use (x-- != 0), but I'll leave that choice up to you.
+ const DeclaratorChunk &DC = D.getTypeObject(x);
+
+ switch (DC.Kind) {
+ case DeclaratorChunk::Paren:
+ continue;
+ case DeclaratorChunk::Array:
+ case DeclaratorChunk::Pointer:
We try to avoid 'default' cases, and this is a good example why. I claim
that there are no declarator chunks which are actually valid here except
Paren. Suppressing the error when the chunk is a Function or BlockPointer
is fine, since we'll still get the more-important diagnostic that the type is
invalid. We should not suppress the error when the chunk is Reference
or MemberPointer, though. Also, if someone adds a new declarator chunk
(not entirely impossible), they should have to consider what to do in this
case.
John.
More information about the cfe-commits
mailing list