https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/121419

>From 3f6b1d68978857035a972f49b1cfd9d9d0151be9 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Wed, 1 Jan 2025 01:47:17 +0200
Subject: [PATCH 1/2] [Clang] emit -Wignored-qualifiers diagnostic for
 cv-qualified base classes

---
 clang/docs/ReleaseNotes.rst                   |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td        |  4 ++++
 clang/lib/Sema/SemaDeclCXX.cpp                |  9 +++++++++
 .../SemaCXX/warn-base-type-qualifiers.cpp     | 20 +++++++++++++++++++
 4 files changed, 34 insertions(+)
 create mode 100644 clang/test/SemaCXX/warn-base-type-qualifiers.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7da12bcf65818..659f0ebd97fc46 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -733,6 +733,7 @@ Improvements to Clang's diagnostics
       scope.Unlock();
       require(scope); // Warning!  Requires mu1.
     }
+- Clang now emits a ``-Wignored-qualifiers`` diagnostic when a base class 
includes cv-qualifiers (#GH55474).
 
 Improvements to Clang's time-trace
 ----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 330ae045616aba..294cfa24975a73 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -487,6 +487,10 @@ def err_noreturn_non_function : Error<
 def warn_qual_return_type : Warning<
   "'%0' type qualifier%s1 on return type %plural{1:has|:have}1 no effect">,
   InGroup<IgnoredQualifiers>, DefaultIgnore;
+def warn_qual_base_type : Warning<
+  "'%0' qualifier%s1 on base class type %2 have no effect">,
+  InGroup<IgnoredQualifiers>, DefaultIgnore;
+
 def warn_deprecated_redundant_constexpr_static_def : Warning<
   "out-of-line definition of constexpr static data member is redundant "
   "in C++17 and is deprecated">,
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index c5a72cf812ebc9..b82ca1541ba249 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2655,6 +2655,15 @@ CXXBaseSpecifier *Sema::CheckBaseSpecifier(CXXRecordDecl 
*Class,
       return nullptr;
     }
 
+    if (BaseType.hasQualifiers() && !isa<SubstTemplateTypeParmType>(BaseType)) 
{
+      auto Quals =
+          BaseType.getQualifiers().getAsString(Context.getPrintingPolicy());
+      Diag(BaseLoc, diag::warn_qual_base_type)
+          << Quals << std::count(Quals.begin(), Quals.end(), ' ') + 1
+          << BaseType;
+      Diag(BaseLoc, diag::note_base_class_specified_here) << BaseType;
+    }
+
     // For the MS ABI, propagate DLL attributes to base class templates.
     if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
         Context.getTargetInfo().getTriple().isPS()) {
diff --git a/clang/test/SemaCXX/warn-base-type-qualifiers.cpp 
b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
new file mode 100644
index 00000000000000..a5af7ec7415bf5
--- /dev/null
+++ b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -std=c++11 -Wignored-qualifiers -verify
+
+class A { };
+
+typedef const A A_Const;
+class B : public A_Const { }; // expected-warning {{'const' qualifier on base 
class type 'A_Const' (aka 'const A') have no effect}} \
+                              // expected-note {{base class 'A_Const' (aka 
'const A') specified here}}
+
+typedef const volatile A A_Const_Volatile;
+class C : public A_Const_Volatile { }; // expected-warning {{'const volatile' 
qualifiers on base class type 'A_Const_Volatile' (aka 'const volatile A') have 
no effect}} \
+                                       // expected-note {{base class 
'A_Const_Volatile' (aka 'const volatile A') specified here}}
+
+struct D {
+  D(int);
+};
+template <typename T> struct E : T {
+  using T::T;
+  E(int &) : E(0) {}
+};
+E<const D> e(1);

>From 397097340707dbefe5f4b07357523ff7ad515304 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.taras...@outlook.com>
Date: Thu, 2 Jan 2025 17:06:05 +0200
Subject: [PATCH 2/2] use explicit variable type

---
 clang/lib/Sema/SemaDeclCXX.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b82ca1541ba249..c4ec7fa4742bdf 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2656,7 +2656,7 @@ CXXBaseSpecifier *Sema::CheckBaseSpecifier(CXXRecordDecl 
*Class,
     }
 
     if (BaseType.hasQualifiers() && !isa<SubstTemplateTypeParmType>(BaseType)) 
{
-      auto Quals =
+      std::string Quals =
           BaseType.getQualifiers().getAsString(Context.getPrintingPolicy());
       Diag(BaseLoc, diag::warn_qual_base_type)
           << Quals << std::count(Quals.begin(), Quals.end(), ' ') + 1

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to