[clang] [NFC] clang add DiagnosticsTestHelper decl (PR #112820)

Jinsong Ji via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 18 08:38:10 PDT 2024


https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112820

>From 53683a8543bb6a558a778dc1cc15adb3180df7e4 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 05:23:19 +0200
Subject: [PATCH 1/4] [NFC] clang add DiagnosticsTestHelper decl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.

Fix warning

llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:19:6: error: ‘void clang::DiagnosticsTestHelper(clang::DiagnosticsEngine&)’ has not been declared within ‘clang’ [-Werror]
   19 | void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
      |      ^~~~~
In file included from /iusers/jinsongj/llvm-project/clang/unittests/Basic/DiagnosticTest.cpp:9:
/iusers/jinsongj/llvm-project/clang/include/clang/Basic/Diagnostic.h:567:15: note: only here as a ‘friend’
  567 |   friend void DiagnosticsTestHelper(DiagnosticsEngine &);
---
 clang/include/clang/Basic/Diagnostic.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 3b1efdb12824c7..3f6e85634c3cf5 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,6 +1024,8 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
   /// @}
 };
 
+void DiagnosticsTestHelper(DiagnosticsEngine &);
+
 /// RAII class that determines when any errors have occurred
 /// between the time the instance was created and the time it was
 /// queried.

>From 677dab12a67b801dd0406e38f092f89b71045785 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 14:54:56 +0200
Subject: [PATCH 2/4] Add comments

---
 clang/include/clang/Basic/Diagnostic.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 3f6e85634c3cf5..dc7e49beb9a0f4 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,6 +1024,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
   /// @}
 };
 
+/// Declare the friend function for testing to avoid GCC warning.
 void DiagnosticsTestHelper(DiagnosticsEngine &);
 
 /// RAII class that determines when any errors have occurred

>From 1154286563d33ffedc4981a1e7c9f72518a1cf6f Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 08:37:38 -0700
Subject: [PATCH 3/4] Revert "Add comments"

This reverts commit 677dab12a67b801dd0406e38f092f89b71045785.
---
 clang/include/clang/Basic/Diagnostic.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index dc7e49beb9a0f4..3f6e85634c3cf5 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,7 +1024,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
   /// @}
 };
 
-/// Declare the friend function for testing to avoid GCC warning.
 void DiagnosticsTestHelper(DiagnosticsEngine &);
 
 /// RAII class that determines when any errors have occurred

>From a40fb059ae8bb81806cc399361c48ea5caca0336 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 08:37:11 -0700
Subject: [PATCH 4/4] Add the decl in unittest file only

---
 clang/include/clang/Basic/Diagnostic.h   | 2 --
 clang/unittests/Basic/DiagnosticTest.cpp | 4 ++++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 3f6e85634c3cf5..3b1efdb12824c7 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1024,8 +1024,6 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
   /// @}
 };
 
-void DiagnosticsTestHelper(DiagnosticsEngine &);
-
 /// RAII class that determines when any errors have occurred
 /// between the time the instance was created and the time it was
 /// queried.
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp b/clang/unittests/Basic/DiagnosticTest.cpp
index 691d74f697f278..54b32bc2bb7833 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -16,6 +16,10 @@
 using namespace llvm;
 using namespace clang;
 
+namespace clang {
+   void DiagnosticsTestHelper(DiagnosticsEngine &diag);
+}
+
 void clang::DiagnosticsTestHelper(DiagnosticsEngine &diag) {
   EXPECT_FALSE(diag.DiagStates.empty());
   EXPECT_TRUE(diag.DiagStatesByLoc.empty());



More information about the cfe-commits mailing list