diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-09-21 21:01:40 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-09-21 22:29:31 +0200 |
commit | 52a49f9e480ca03e231cfda82640a928393131c9 (patch) | |
tree | f685aaeec9787e9f5aa2940514c4533b1a59bc86 /compilerplugins | |
parent | e79a6a5270d190d6e89a6acf08e22419386d2117 (diff) |
static_assert that O[U]StringLiteral are layout compatible with rtl_[u]String
...as was suggested by Mike Kaganski in a comment at
<https://gerrit.libreoffice.org/c/core/+/102222/10#
message-aa8bcf42f04686766440e2848c7d1f76f474f2f8> "Turn OUStringLiteral into a
consteval'ed, static-refcound rtl_uString". Doing so revealed that at least
lopglugin:unusedmember needs to handle InjectedClassNameType as an alternative
to RecordType in at least one place. (More places across compilerplugins might
benefit from handling InjectedClassNameType too, but which did not lead to
assertion failures for now and should be addressed in follow-up issues.)
Change-Id: Icdb8b069324b5ce5f3c7c6b92989379ccb67fc8b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103125
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/unusedmember.cxx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/compilerplugins/clang/unusedmember.cxx b/compilerplugins/clang/unusedmember.cxx index a32fd341c665..1d3017134892 100644 --- a/compilerplugins/clang/unusedmember.cxx +++ b/compilerplugins/clang/unusedmember.cxx @@ -240,7 +240,17 @@ public: { return true; } - recordRecordDeclAndBases(expr->getTypeSourceInfo()->getType()->castAs<RecordType>()); + auto const t1 = expr->getTypeSourceInfo()->getType(); + RecordDecl const* d; + if (auto const t2 = t1->getAs<InjectedClassNameType>()) + { + d = t2->getDecl(); + } + else + { + d = t1->castAs<RecordType>()->getDecl(); + } + recordRecordDeclAndBases(d); return true; } @@ -276,7 +286,7 @@ public: } if (auto const t1 = t->getAs<RecordType>()) { - recordRecordDeclAndBases(t1); + recordRecordDeclAndBases(t1->getDecl()); } return true; } @@ -406,18 +416,17 @@ private: return t.isTrivialType(compiler.getASTContext()) || isWarnUnusedType(t); } - void recordRecordDeclAndBases(RecordType const* type) + void recordRecordDeclAndBases(RecordDecl const* decl) { - auto const d1 = type->getDecl(); - if (!layout_.insert(d1->getCanonicalDecl()).second) + if (!layout_.insert(decl->getCanonicalDecl()).second) { return; } - if (auto const d2 = dyn_cast_or_null<CXXRecordDecl>(d1->getDefinition())) + if (auto const d2 = dyn_cast_or_null<CXXRecordDecl>(decl->getDefinition())) { for (auto i = d2->bases_begin(); i != d2->bases_end(); ++i) { - recordRecordDeclAndBases(i->getType()->castAs<RecordType>()); + recordRecordDeclAndBases(i->getType()->castAs<RecordType>()->getDecl()); } //TODO: doesn't iterate vbases, but presence of such would run counter to the layout // heuristic anyway @@ -435,7 +444,7 @@ private: } if (auto const t1 = t->getAs<RecordType>()) { - recordRecordDeclAndBases(t1); + recordRecordDeclAndBases(t1->getDecl()); } break; } |