bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / subtlezeroinit.cxx
blobb1b91c8477d5e50d47caa8f1f3e5b09c0bdbe402
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include "plugin.hxx"
14 // Find occurrences of 'new T()' where the instance is zero-initialized upfront
15 // since C++11. For one, in many cases this may be unnecessary and unintended,
16 // as the code was written before C++11. For another, the zero-initialization
17 // would go away when T gets a user-provided default constructor, for example,
18 // so better make any necessary initialization more explicit in the code.
20 namespace {
22 class SubtleZeroInit final:
23 public loplugin::FilteringPlugin<SubtleZeroInit>
25 public:
26 explicit SubtleZeroInit(loplugin::InstantiationData const & data):
27 FilteringPlugin(data) {}
29 bool VisitCXXNewExpr(CXXNewExpr const * expr) {
30 if (ignoreLocation(expr)) {
31 return true;
33 auto ce = expr->getConstructExpr();
34 if (ce == nullptr) {
35 return true;
37 if (!ce->requiresZeroInitialization()) {
38 return true;
40 report(
41 DiagnosticsEngine::Warning,
42 ("if zero-initialization of %0 is intentional here, better make"
43 " that more explicit (e.g., assigning to members, default"
44 " constructor, default member initializers, std::memset)"),
45 expr->getExprLoc())
46 << ce->getType() << expr->getSourceRange();
47 return true;
50 virtual bool preRun() override {
51 return compiler.getLangOpts().CPlusPlus;
54 virtual void run() override {
55 if (preRun()) {
56 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
61 static loplugin::Plugin::Registration<SubtleZeroInit> subtlezeroinit("subtlezeroinit");
65 #endif // LO_CLANG_SHARED_PLUGINS
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */