Enable ClangTidy check modernize-use-nullptr.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
The check converts the usage of null pointer constants (eg. NULL, 0) to
use the new C++11 nullptr keyword.
Change-Id: Iaea2d843154c70e49d62affdc5dceb3bca8c1089
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310297
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/.clang-tidy b/.clang-tidy
index 7c4b363..cb38913 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -9,6 +9,7 @@
llvm-namespace-comment,
misc-definitions-in-headers,
modernize-make-unique,
+ modernize-use-nullptr,
modernize-use-override,
performance-for-range-copy,
performance-unnecessary-copy-initialization,
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index f99dfdf..c8e3cb2 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -483,7 +483,9 @@
/** @return false or true based on the condition
*/
-template <typename T> static constexpr bool SkToBool(const T& x) { return 0 != x; }
+template <typename T> static constexpr bool SkToBool(const T& x) {
+ return 0 != x; // NOLINT(modernize-use-nullptr)
+}
static constexpr int16_t SK_MaxS16 = INT16_MAX;
static constexpr int16_t SK_MinS16 = -SK_MaxS16;
diff --git a/include/gpu/GrBackendSemaphore.h b/include/gpu/GrBackendSemaphore.h
index c3e60fb..b7043bf 100644
--- a/include/gpu/GrBackendSemaphore.h
+++ b/include/gpu/GrBackendSemaphore.h
@@ -24,7 +24,8 @@
public:
// For convenience we just set the backend here to OpenGL. The GrBackendSemaphore cannot be used
// until either initGL or initVulkan are called which will set the appropriate GrBackend.
- GrBackendSemaphore() : fBackend(GrBackendApi::kOpenGL), fGLSync(0), fIsInitialized(false) {}
+ GrBackendSemaphore()
+ : fBackend(GrBackendApi::kOpenGL), fGLSync(nullptr), fIsInitialized(false) {}
#ifdef SK_DIRECT3D
// We only need to specify these if Direct3D is enabled, because it requires special copy
@@ -75,7 +76,7 @@
GrGLsync glSync() const {
if (!fIsInitialized || GrBackendApi::kOpenGL != fBackend) {
- return 0;
+ return nullptr;
}
return fGLSync;
}
diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/mac/SkCGUtils.h
index 43cd59f..a320dd8 100644
--- a/include/utils/mac/SkCGUtils.h
+++ b/include/utils/mac/SkCGUtils.h
@@ -63,7 +63,7 @@
* by CGColorSpaceCreateDeviceRGB()
*/
static inline CGImageRef SkCreateCGImageRef(const SkBitmap& bm) {
- return SkCreateCGImageRefWithColorspace(bm, NULL);
+ return SkCreateCGImageRefWithColorspace(bm, nil);
}
/**
diff --git a/modules/skparagraph/src/FontCollection.cpp b/modules/skparagraph/src/FontCollection.cpp
index f5802df..835e4bd 100644
--- a/modules/skparagraph/src/FontCollection.cpp
+++ b/modules/skparagraph/src/FontCollection.cpp
@@ -119,7 +119,7 @@
bcp47.push_back(locale.c_str());
}
sk_sp<SkTypeface> typeface(manager->matchFamilyStyleCharacter(
- 0, fontStyle, bcp47.data(), bcp47.size(), unicode));
+ nullptr, fontStyle, bcp47.data(), bcp47.size(), unicode));
if (typeface != nullptr) {
return typeface;
}
diff --git a/modules/sksg/include/SkSGRenderEffect.h b/modules/sksg/include/SkSGRenderEffect.h
index fb24ff6..aa0d413 100644
--- a/modules/sksg/include/SkSGRenderEffect.h
+++ b/modules/sksg/include/SkSGRenderEffect.h
@@ -57,7 +57,7 @@
public:
~ShaderEffect() override;
- static sk_sp<ShaderEffect> Make(sk_sp<RenderNode> child, sk_sp<Shader> shader = 0);
+ static sk_sp<ShaderEffect> Make(sk_sp<RenderNode> child, sk_sp<Shader> shader = nullptr);
void setShader(sk_sp<Shader>);
@@ -107,7 +107,7 @@
}
protected:
- explicit ImageFilter(sk_sp<ImageFilter> input = 0);
+ explicit ImageFilter(sk_sp<ImageFilter> input = nullptr);
using InputsT = std::vector<sk_sp<ImageFilter>>;
explicit ImageFilter(std::unique_ptr<InputsT> inputs);
diff --git a/src/c/sk_surface.cpp b/src/c/sk_surface.cpp
index f98f824..ca4c51f 100644
--- a/src/c/sk_surface.cpp
+++ b/src/c/sk_surface.cpp
@@ -324,7 +324,7 @@
void sk_canvas_draw_picture(sk_canvas_t* ccanvas, const sk_picture_t* cpicture,
const sk_matrix_t* cmatrix, const sk_paint_t* cpaint) {
- const SkMatrix* matrixPtr = NULL;
+ const SkMatrix* matrixPtr = nullptr;
SkMatrix matrix;
if (cmatrix) {
from_c_matrix(cmatrix, &matrix);
@@ -340,7 +340,7 @@
const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
SkPixelGeometry geo = kUnknown_SkPixelGeometry;
if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
- return NULL;
+ return nullptr;
}
SkSurfaceProps surfProps(0, geo);
@@ -353,7 +353,7 @@
const SkImageInfo* info = reinterpret_cast<const SkImageInfo*>(cinfo);
SkPixelGeometry geo = kUnknown_SkPixelGeometry;
if (props && !from_c_pixelgeometry(props->pixelGeometry, &geo)) {
- return NULL;
+ return nullptr;
}
SkSurfaceProps surfProps(0, geo);
diff --git a/src/gpu/gl/GrGLSemaphore.cpp b/src/gpu/gl/GrGLSemaphore.cpp
index 4ddfee8..32fd636 100644
--- a/src/gpu/gl/GrGLSemaphore.cpp
+++ b/src/gpu/gl/GrGLSemaphore.cpp
@@ -10,7 +10,7 @@
#include "src/gpu/gl/GrGLGpu.h"
GrGLSemaphore::GrGLSemaphore(GrGLGpu* gpu, bool isOwned)
- : fGpu(gpu), fSync(0), fIsOwned(isOwned) {
+ : fGpu(gpu), fSync(nullptr), fIsOwned(isOwned) {
}
GrGLSemaphore::~GrGLSemaphore() {
diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp
index 98b24db..14c8e49 100644
--- a/src/gpu/vk/GrVkImage.cpp
+++ b/src/gpu/vk/GrVkImage.cpp
@@ -243,7 +243,7 @@
imageDesc.fUsageFlags, // VkImageUsageFlags
VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode
0, // queueFamilyCount
- 0, // pQueueFamilyIndices
+ nullptr, // pQueueFamilyIndices
initialLayout // initialLayout
};
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 1023b2d..29cb4bb 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -184,7 +184,7 @@
VkPipelineLayoutCreateInfo layoutCreateInfo;
memset(&layoutCreateInfo, 0, sizeof(VkPipelineLayoutCreateFlags));
layoutCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
- layoutCreateInfo.pNext = 0;
+ layoutCreateInfo.pNext = nullptr;
layoutCreateInfo.flags = 0;
layoutCreateInfo.setLayoutCount = 2;
layoutCreateInfo.pSetLayouts = dsLayout;
diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp
index a3209af..f6a6af5 100644
--- a/src/utils/SkPolyUtils.cpp
+++ b/src/utils/SkPolyUtils.cpp
@@ -896,7 +896,7 @@
} else {
ActiveEdge *s = parent->fChild[!last];
- if (s != NULL) {
+ if (s != nullptr) {
if (!IsRed(s->fChild[!last]) && !IsRed(s->fChild[last])) {
// color flip
parent->fRed = false;
diff --git a/tests/CTest.cpp b/tests/CTest.cpp
index 9c0868d..e73cc24 100644
--- a/tests/CTest.cpp
+++ b/tests/CTest.cpp
@@ -18,7 +18,7 @@
static void shader_test(skiatest::Reporter* reporter) {
sk_imageinfo_t* info = sk_imageinfo_new(64, 64, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
- NULL);
+ nullptr);
sk_surface_t* surface = sk_surface_new_raster(info, nullptr);
sk_canvas_t* canvas = sk_surface_get_canvas(surface);
sk_paint_t* paint = sk_paint_new();
@@ -59,7 +59,7 @@
static void test_c(skiatest::Reporter* reporter) {
sk_imageinfo_t* info = sk_imageinfo_new(1, 1, RGBA_8888_SK_COLORTYPE, PREMUL_SK_ALPHATYPE,
- NULL);
+ nullptr);
uint32_t pixel[1] = { 0 };
sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index 76f625a..73ab6d1 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -1547,7 +1547,7 @@
sk_sp<GrTextureProxy> GrClipStackClip::testingOnly_createClipMask(
GrRecordingContext* context) const {
- const GrReducedClip reducedClip(*fStack, SkRect::MakeWH(512, 512), 0);
+ const GrReducedClip reducedClip(*fStack, SkRect::MakeWH(512, 512), nullptr);
return this->createSoftwareClipMask(context, reducedClip, nullptr).asTextureProxyRef();
}
diff --git a/tests/InterpolatorTest.cpp b/tests/InterpolatorTest.cpp
index 813d2bf..b56a05b 100644
--- a/tests/InterpolatorTest.cpp
+++ b/tests/InterpolatorTest.cpp
@@ -21,7 +21,7 @@
SkScalar v1[3], v2[3], v[3];
SkInterpolator::Result result;
- inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), 0);
+ inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), nullptr);
inter.setKeyFrame(1, 200, iset(v2, 110, 220, 330));
result = inter.timeToValues(0, v);
diff --git a/tests/Matrix44Test.cpp b/tests/Matrix44Test.cpp
index 254a41c..28f7d76 100644
--- a/tests/Matrix44Test.cpp
+++ b/tests/Matrix44Test.cpp
@@ -94,7 +94,7 @@
}
// Verify that kIdentity_Constructor really does initialize to an identity matrix.
- testMatrix = 0;
+ testMatrix = nullptr;
testMatrix = new(placeholderMatrix) SkMatrix44(SkMatrix44::kIdentity_Constructor);
REPORTER_ASSERT(reporter, testMatrix == placeholderMatrix);
REPORTER_ASSERT(reporter, testMatrix->isIdentity());
diff --git a/tests/PathOpsOpTest.cpp b/tests/PathOpsOpTest.cpp
index 014bad9..7c0aa28 100644
--- a/tests/PathOpsOpTest.cpp
+++ b/tests/PathOpsOpTest.cpp
@@ -9103,9 +9103,9 @@
testPathOp(reporter, path, path2, kIntersect_SkPathOp, filename);
}
-static void (*skipTest)(skiatest::Reporter* , const char* filename) = 0;
-static void (*firstTest)(skiatest::Reporter* , const char* filename) = 0;
-static void (*stopTest)(skiatest::Reporter* , const char* filename) = 0;
+static void (*skipTest)(skiatest::Reporter* , const char* filename) = nullptr;
+static void (*firstTest)(skiatest::Reporter* , const char* filename) = nullptr;
+static void (*stopTest)(skiatest::Reporter* , const char* filename) = nullptr;
#define TEST(name) { name, #name }
diff --git a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
index 57d87bc..51ee263 100644
--- a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
+++ b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
@@ -205,7 +205,7 @@
if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_context"),
reinterpret_cast<const GLubyte*>(glxExts))) {
if (kGLES_GrGLStandard != forcedGpuAPI) {
- fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
+ fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, nullptr, True);
}
} else {
if (kGLES_GrGLStandard == forcedGpuAPI) {
diff --git a/tools/sk_app/VulkanWindowContext.cpp b/tools/sk_app/VulkanWindowContext.cpp
index 14bbb28..968b4ac 100644
--- a/tools/sk_app/VulkanWindowContext.cpp
+++ b/tools/sk_app/VulkanWindowContext.cpp
@@ -537,13 +537,13 @@
const VkPresentInfoKHR presentInfo =
{
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, // sType
- NULL, // pNext
+ nullptr, // pNext
1, // waitSemaphoreCount
&backbuffer->fRenderSemaphore, // pWaitSemaphores
1, // swapchainCount
&fSwapchain, // pSwapchains
&backbuffer->fImageIndex, // pImageIndices
- NULL // pResults
+ nullptr // pResults
};
fQueuePresentKHR(fPresentQueue, &presentInfo);
diff --git a/tools/sk_app/mac/main_mac.mm b/tools/sk_app/mac/main_mac.mm
index f200abf..bf6da11 100644
--- a/tools/sk_app/mac/main_mac.mm
+++ b/tools/sk_app/mac/main_mac.mm
@@ -60,7 +60,7 @@
NSMenuItem* item;
NSMenu* subMenu;
- item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""];
+ item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:nil keyEquivalent:@""];
[menuBar addItem:item];
subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
[menuBar setSubmenu:subMenu forItem:item];