Bug 1828719 - Remove omnijar Gradle project from srcdir r=geckoview-reviewers,nalexan...
[gecko.git] / build / clang-plugin / TrivialCtorDtorChecker.cpp
blob59576a5b6418eec055100a4f7c9eee6f7b19d8bb
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "TrivialCtorDtorChecker.h"
6 #include "CustomMatchers.h"
8 void TrivialCtorDtorChecker::registerMatchers(MatchFinder *AstMatcher) {
9 AstMatcher->addMatcher(cxxRecordDecl(hasTrivialCtorDtor()).bind("node"),
10 this);
13 void TrivialCtorDtorChecker::check(const MatchFinder::MatchResult &Result) {
14 const char *Error = "class %0 must have trivial constructors and destructors";
15 const CXXRecordDecl *Node = Result.Nodes.getNodeAs<CXXRecordDecl>("node");
17 if (!Node->hasDefinition()) {
18 return;
21 // We need to accept non-constexpr trivial constructors as well. This occurs
22 // when a struct contains pod members, which will not be initialized. As
23 // constexpr values are initialized, the constructor is non-constexpr.
24 bool BadCtor = !(Node->hasConstexprDefaultConstructor() ||
25 Node->hasTrivialDefaultConstructor());
26 bool BadDtor = !Node->hasTrivialDestructor();
27 if (BadCtor || BadDtor)
28 diag(Node->getBeginLoc(), Error, DiagnosticIDs::Error) << Node;