[PATCH] D18649: [clang-tidy] cppcoreguidelines-interfaces-global-init

Clement Courbet via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 4 00:19:02 PDT 2016


courbet added a comment.

In http://reviews.llvm.org/D18649#389363, @alexfh wrote:

> Thank you for working on the new clang-tidy check!
>
> We usually recommend authors to run their checks on a large code base to ensure it doesn't crash and doesn't generate obvious false positives. It would be nice, if you could provide a quick summary of such a run (total number of hits, number of what seems to be a false positive in a sample of ~100).


The tool generated 20k positives on our codebase. On a sample of 100, there are:

- 8 instances of the same exact code structure that's just wrong: const string var = FLAGS_some_flag + "some_sufix";
- 8 false positives.
- 84 possible issues. (interestingly 6 of these are from premature use of variations of "extern char* empty_string;"

The false positives fall into 3 categories:

1. 3 variations of:

extern int i;
static const int* pi = &i;  // diag
// Then pi is dereferenced later, once i is intialized. 
Public example of this: https://github.com/python-git/python/blob/py3k/Objects/dictobject.c#L2027

2. 3 variations of:

// .h
class A {

  static const int i = 42;

};
// .cc
int A::i;  // diag

3. 2 variations of:

// .h
class A {
static int i;
static int j;
};
// .cc
int A::i = 0;
int A::j = i;  // diag


http://reviews.llvm.org/D18649





More information about the cfe-commits mailing list