Clang Project

clang_source_code/test/Analysis/padding_inherit.cpp
1// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=20 -verify %s
2
3// A class that has no fields and one base class should visit that base class
4// instead. Note that despite having excess padding of 2, this is flagged
5// because of its usage in an array of 100 elements below (`ais').
6// TODO: Add a note to the bug report with BugReport::addNote() to mention the
7// variable using the class and also mention what class is inherting from what.
8// expected-warning@+1{{Excessive padding in 'struct FakeIntSandwich'}}
9struct FakeIntSandwich {
10  char c1;
11  int i;
12  char c2;
13};
14
15struct AnotherIntSandwich : FakeIntSandwich { // no-warning
16};
17
18// But we don't yet support multiple base classes.
19struct IntSandwich {};
20struct TooManyBaseClasses : FakeIntSandwich, IntSandwich { // no-warning
21};
22
23AnotherIntSandwich ais[100];
24
25struct Empty {};
26struct DoubleEmpty : Empty { // no-warning
27    Empty e;
28};
29