[cfe-commits] [Patch] Produce errors for 'static' and type qualifiers in array declarators

Eli Friedman eli.friedman at gmail.com
Mon Aug 6 11:47:14 PDT 2012


On Mon, Aug 6, 2012 at 11:12 AM, Hans Wennborg <hans at chromium.org> wrote:
> As mentioned in a recent cfe-dev thread [1], Clang currently fails to
> produce errors for using 'static' and type qualifiers in array
> declarators outside of function prototypes. For example:
>
> void f(int x[static 42]) { // <-- This is fine.
>   int a[static 42]; // <-- This should be an error.
> }
>
> Attached is my attempt to fix this.
>
> One thing I was uncertain of is what to do when the code has multiple
> errors. For example, if it has 'static' in an array declarator that is
> both outside a function prototype, and also not in the first pair of
> brackets. Currently, my patch only gives one error.

That's fine.

> Please take a look.

+      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.

-Eli



More information about the cfe-commits mailing list