This patch adds warning on structures/unions that are empty or contain
only bit fields of zero size. Warnings are generated in C++ mode and
if only such type is defined inside extern "C" block.
The patch fixed PR5065.
Details
Diff Detail
Event Timeline
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
5721 | Maybe name this warn_..._union_in_extern_c or similar? | |
lib/Sema/SemaDecl.cpp | ||
12074–12075 | You could also check that Record->getDeclContext()->getRedeclContext()->isFileContext() here (that is, it's not a local class nor a member class). | |
12076 | This is redundant. In CPlusPlus mode, every RecordDecl is a CXXRecordDecl. | |
12105 | Non-static data members can't have deduced types, so this is impossible. | |
12111–12132 | It would be simpler to organize this as: if (ZeroSize) Diag(..., getLangOpts().CPlusPlus ? diag::..._extern_c : diag::..._compat) ... if (NonBitFields == 0 && !getLangOpts().CPlusPlus) { ... } |
Thank you for review.
include/clang/Basic/DiagnosticSemaKinds.td | ||
---|---|---|
5721 | Renamed. | |
lib/Sema/SemaDecl.cpp | ||
12074–12075 | With this check the warning for inner struct would be absent in the following declaration: struct pr5065_n2 { struct Inner {} x; } q; Expression sizeof(q.x) would give different results in C and C++. | |
12076 | The check is removed. | |
12105 | Removed. |
LGTM
lib/Sema/SemaDecl.cpp | ||
---|---|---|
12074–12075 | OK, that's fair. On the other hand, this code means different things in C and C++ (in C, 'Inner' is a top-level type, not a nested type). Maybe we should have a separate warning for that? |
Maybe name this warn_..._union_in_extern_c or similar?