Skip to content
Mathiasdm edited this page Sep 10, 2011 · 36 revisions

Goal

Create a few useful additions to Eclipse CDT. Current target: static code checkers.

First try (to learn): detecting unneeded header guards.

Example:

a.h:
#ifndef A_H
#define A_H
int foo();
#endif

b.h:
#ifndef A_H
#include "a.h"
#endif

int bar();

TODO:

  • Add unit tests for included headers that are in the 'Includes', not part of the 'Source Location' list.

Other possible static code checkers

  • Includes:
    • Check if included header is used
    • Check if a transitive header include is done (A includes B, B includes C. A needs C, but not B).
  • Better solution for includes:
    • Go over all the types in the file, checking in which file they are defined. Propose 'add include' for the files in which they are defined.
    • Go over all the types in the files, checking in which file they are defined. All the files that do not have any types referenced, are marked as not needed.
    • The above two checkers can be run, resulting in a 'clean up includes'.
  • Check if header contains proper internal header guards.
  • Check if a function returns a local variable.
  • Check for statically created arrays being compared with NULL: http://stackoverflow.com/questions/3857229/check-if-c-array-is-null
  • Check for variable declaration within switch statement: http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement

Other interesting topics

int a; someFunction(a);

void someFunction(int a) {
    //use a
}

Becomes:
someFunction();

void someFunction() {
    int a;
    //use a
}
  • char* concatenation should cause a warning if it happens in an array of char*'s. Example:

char* foo[] = { "aaaaaaaaaa", "bbbbbbbbbb" //Give warning here "cccccccccc" };

  • Code folding in methods (for example on an 'if')
  • Add namespace in header guard

Unneeded topics (that are already implemented in Eclipse CDT)

  • Hiding '#include' in the outline view (you can use 'Group includes')