[PATCH] D19769: [clang-tidy] Add explicitly given array size heuristic to misc-suspicious-missing-comma check.

Etienne Bergeron via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 19:35:46 PDT 2016


etienneb requested changes to this revision.
etienneb added a comment.
This revision now requires changes to proceed.

If the 'original' size is available, the checkers should by-pass the heuristic.
Can you check if there is a way to get the original size.


================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:106
@@ +105,3 @@
+  if (InitializerList->hasArrayFiller()) {
+      diag(InitializerList->getExprLoc(),
+           "wrong string array initialization: "
----------------
szdominik wrote:
> etienneb wrote:
> > The error should still be reported to the missing comma (concatenated token):
> >   ConcatenatedLiteral->getLocStart(),
> > 
> > We could add a NOTE to point to the array, stating that the size mismatch.
> > 
> > What do you think?
> Interesting question (the first idea was that we can't decide that the comma is missing or the size is wrong, so report to the array, that's a more secure solution), but I agree that the note could be more effective.
> And... it's still a suspicious-missing-comma checker, not a wrong-string-array-size checker :)
How can you be sure the size was provided by the user? And not inferred by the type system?

For the following examples:
```
const char* listA[] = {"a", "b" };
const char* listB[5] = {"a", "b" };
```

We've got this:
```
VarDecl 0x5e9d840 <C:\src\llvm\examples\hello_world.cc:11:1, col:33> col:13 listA 'const char *[2]' cinit
`-InitListExpr 0x5e9d950 <col:23, col:33> 'const char *[2]'
  |-ImplicitCastExpr 0x5e9d978 <col:24> 'const char *' <ArrayToPointerDecay>
  | `-StringLiteral 0x5e9d8d8 <col:24> 'const char [2]' lvalue "a"
  `-ImplicitCastExpr 0x5e9d988 <col:29> 'const char *' <ArrayToPointerDecay>
    `-StringLiteral 0x5e9d8fc <col:29> 'const char [2]' lvalue "b"
```

```
VarDecl 0x5e9d840 <C:\src\llvm\examples\hello_world.cc:11:1, col:33> col:13 listA 'const char *[2]' cinit
`-InitListExpr 0x5e9d950 <col:23, col:33> 'const char *[2]'
  |-ImplicitCastExpr 0x5e9d978 <col:24> 'const char *' <ArrayToPointerDecay>
  | `-StringLiteral 0x5e9d8d8 <col:24> 'const char [2]' lvalue "a"
  `-ImplicitCastExpr 0x5e9d988 <col:29> 'const char *' <ArrayToPointerDecay>
    `-StringLiteral 0x5e9d8fc <col:29> 'const char [2]' lvalue "b"
```

How can I tell the "size" was written by the user?
How can you get the "5" and not the "2".



http://reviews.llvm.org/D19769





More information about the cfe-commits mailing list