https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/188420
None >From 5ab10f40b4810629ef6a902ea9090df2aec1e524 Mon Sep 17 00:00:00 2001 From: mtx <[email protected]> Date: Wed, 25 Mar 2026 15:11:10 +0800 Subject: [PATCH] [clang-tidy][NFC] Use mock header instead of #define NULL in tests --- .../test/clang-tidy/checkers/android/cloexec-accept.cpp | 2 +- .../test/clang-tidy/checkers/android/cloexec-accept4.cpp | 2 +- .../test/clang-tidy/checkers/android/cloexec-memfd-create.cpp | 2 +- .../test/clang-tidy/checkers/android/cloexec-pipe2.cpp | 2 +- .../test/clang-tidy/checkers/bugprone/posix-return.cpp | 2 +- .../checkers/bugprone/spuriously-wake-up-functions.c | 2 +- .../checkers/bugprone/spuriously-wake-up-functions.cpp | 2 +- .../test/clang-tidy/checkers/modernize/redundant-void-arg.c | 2 +- .../test/clang-tidy/checkers/modernize/redundant-void-arg.cpp | 2 +- .../test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp | 2 +- .../test/clang-tidy/checkers/modernize/use-nullptr-c23.c | 2 +- .../test/clang-tidy/checkers/modernize/use-nullptr.c | 2 +- .../test/clang-tidy/checkers/modernize/use-nullptr.cpp | 2 +- .../clang-tidy/checkers/readability/delete-null-pointer.cpp | 2 +- .../clang-tidy/checkers/readability/implicit-bool-conversion.c | 3 +-- .../clang-tidy/checkers/readability/isolate-declaration.cpp | 2 +- .../checkers/readability/redundant-smartptr-get-msvc.cpp | 2 +- .../clang-tidy/checkers/readability/redundant-smartptr-get.cpp | 2 +- 18 files changed, 18 insertions(+), 19 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp index 9990594266bfd..159e3960ecaac 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept.cpp @@ -2,7 +2,7 @@ struct sockaddr {}; typedef int socklen_t; -#define NULL 0 +#include <cstddef> extern "C" int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp index 448d4a9f6404b..d113561220862 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-accept4.cpp @@ -13,7 +13,7 @@ struct sockaddr {}; _rc = (exp); \ } while (_rc == -1); \ }) -#define NULL 0 +#include <cstddef> extern "C" int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp index d1d77d35392c8..5f0be4b47ebac 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-memfd-create.cpp @@ -10,7 +10,7 @@ _rc = (exp); \ } while (_rc == -1); \ }) -#define NULL 0 +#include <cstddef> extern "C" int memfd_create(const char *name, unsigned int flags); diff --git a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp index 4bda70fa77cc5..177be03395c4d 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/android/cloexec-pipe2.cpp @@ -10,7 +10,7 @@ _rc = (exp); \ } while (_rc == -1); \ }) -#define NULL 0 +#include <cstddef> extern "C" int pipe2(int pipefd[2], int flags); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp index d0dfd978b7c37..043b5703cdf98 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/posix-return.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s bugprone-posix-return %t -#define NULL nullptr +#include <cstddef> #define ZERO 0 #define NEGATIVE_ONE -1 diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c index 36b1215978603..1dbc333963ed1 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.c @@ -1,5 +1,5 @@ // RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- -- -#define NULL 0 +#include <stddef.h> struct Node1 { void *Node1; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp index d7508009e19ad..4e265b64ae524 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/spuriously-wake-up-functions.cpp @@ -1,5 +1,5 @@ // RUN: %check_clang_tidy %s bugprone-spuriously-wake-up-functions %t -- -- -#define NULL 0 +#include <cstddef> namespace std { using intmax_t = int; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c index 8eb874a33c101..bf84aa327fae7 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.c @@ -3,7 +3,7 @@ // RUN: clang-tidy %s -checks=-*,modernize-redundant-void-arg -- -std=c17 -Wno-strict-prototypes | count 0 // RUN: %check_clang_tidy -std=c23-or-later -check-suffixes=C23 %s modernize-redundant-void-arg %t -#define NULL 0 +#include <stddef.h> extern int i; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp index 09dc2bb5c1775..a029cd997bdc6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/redundant-void-arg.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s modernize-redundant-void-arg %t -#define NULL 0 +#include <cstddef> int foo(); diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp index b9ffeecf2bafc..7b92cbd9b7608 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-basic.cpp @@ -1,7 +1,7 @@ // RUN: %check_clang_tidy %s modernize-use-nullptr %t -- -- -fno-delayed-template-parsing const unsigned int g_null = 0; -#define NULL 0 +#include <cstddef> void test_assignment() { int *p1 = 0; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c index d9b7ec2f7d190..9097b93232dcd 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr-c23.c @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy -std=c23-or-later %s modernize-use-nullptr %t -#define NULL 0 +#include <stddef.h> void test_assignment() { int *p1 = 0; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c index 1218b837199c0..5f659319f3546 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.c @@ -3,7 +3,7 @@ // Note: this test expects no diagnostics, but FileCheck cannot handle that, // hence the use of | count 0. -#define NULL 0 +#include <stddef.h> void f(void) { char *str = NULL; // ok (void)str; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp index 27a96297c4119..0092a5cc9a47b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-nullptr.cpp @@ -1,7 +1,7 @@ // RUN: %check_clang_tidy %s modernize-use-nullptr %t -- \ // RUN: -config="{CheckOptions: {modernize-use-nullptr.NullMacros: 'MY_NULL,NULL'}}" -#define NULL 0 +#include <cstddef> namespace std { diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp index 1a37c2bbf1133..b8221c1e296de 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/delete-null-pointer.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s readability-delete-null-pointer %t -- -- -fno-delayed-template-parsing -#define NULL 0 +#include <cstddef> template <typename T> struct Templ { diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c index e6f8eb451f67a..67b9f906f888b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c @@ -4,8 +4,7 @@ // RUN: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix: true \ // RUN: }}' -#undef NULL -#define NULL 0L +#include <stddef.h> void functionTakingBool(bool); void functionTakingInt(int); diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp index ce3a0da796559..b7eea73041cb3 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration.cpp @@ -190,7 +190,7 @@ void forbidden_transformations() { ; } -#define NULL 0 +#include <cstddef> #define MY_NICE_TYPE int ** #define VAR_NAME(name) name##__LINE__ #define A_BUNCH_OF_VARIABLES int m1 = 42, m2 = 43, m3 = 44; diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp index b360ccbadfa5f..bccb1a2285506 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get-msvc.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t -#define NULL __null +#include <cstddef> namespace std { diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp index b74d28f4873bb..77497594fa211 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp @@ -2,7 +2,7 @@ #include <vector> #include <memory> -#define NULL __null +#include <cstddef> struct Bar { void Do(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
