-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang] add emit -Wignored-base-class-qualifiers diagnostic for cv-qualified base classes #132116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@erichkeane , I've added what I think is the correct approach for #131935 by adding a new group to DiagnosticGroups.td Not sure on what the best name is for the new group, so added "IgnoredCVQualifiers" for the time being Let me know if this is going in the right direction - feedback would be appreciated and set as a draft PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I think ends up being the 'minimum' patch here, but see my suggestion on the bug:
I also believe there is value to only diagnosing this on EXPLICIT qualifiers (or a separate, additional warning to do so), not ones that get picked up from the template.
The more I think about it, the more I think that we should modify the warning to only happen on EXPLICIT qualifiers. So:
struct Base{};
using CBase = const Base;
struct D1 : const Base {}; // DOES warn
struct D2 : CBase{}; // a DIFFERENT warning (same wording perhaps?) under a different group.
template<typename T> Templ: const T{};
Templ<Base> t; // Causes same warning as D1.
template<typename T> Templ2 : T{};
Templ2<CBase> t; // Causes same warning as D2.
If you search for where that diagnostic is emitted, you should see that. You might have to do some debugging to figure out how to differentiate the cases though.
clang/docs/ReleaseNotes.rst
Outdated
@@ -284,6 +284,8 @@ Improvements to Clang's diagnostics | |||
|
|||
- Improve the ``-Wundefined-func-template`` warning when a function template is not instantiated due to being unreachable in modules. | |||
|
|||
- Clang now emits a ``-Wignored-cv-qualifiers`` diagnostic when a base class includes cv-qualifiers ([toadd]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is [toadd]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on the original PR release note i saw a reference to the feature number i.e (#GH55474) and wasn't sure if i needed to add it here - removed it
@@ -497,6 +497,7 @@ def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">; | |||
def IgnoredGCH : DiagGroup<"ignored-gch">; | |||
def IgnoredReferenceQualifiers : DiagGroup<"ignored-reference-qualifiers">; | |||
def IgnoredQualifiers : DiagGroup<"ignored-qualifiers", [IgnoredReferenceQualifiers]>; | |||
def IgnoredCVQualifiers : DiagGroup<"ignored-cv-qualifiers", [IgnoredReferenceQualifiers]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably choose a better name for this group. I think it should be clear that this is for base classes, it isn't cv qualifiers, it is base classes.
So something like ignored-base-class-qualifiers
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this, so all references will be to ignored-base-class-qualifiers
now
Please also be sure to add enough information to the PR summary to explain why the changes are needed (the summary becomes the commit message). |
Adding qualifiers directly in base specifiers is invalid (and all major compilers correctly reject this). See grammar in [class.derived.general]/1. Qualifiers can indirectly come from |
Ah, cool. I didn't realize we rejected that already. Then I think adding this to a new flag is sufficient, so probably OK after Aaron + My comments are addressed. |
I've addressed the comments @erichkeane , so its now @AaronBallman , let me know if that summary isn't sufficient |
@llvm/pr-subscribers-clang Author: Lyle Dean (lyledean1) ChangesThis splits base class qualifiers from ignored qualifiers Full diff: https://github.com/llvm/llvm-project/pull/132116.diff 4 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9b0680c68b83a..82afde2a8d229 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -284,6 +284,8 @@ Improvements to Clang's diagnostics
- Improve the ``-Wundefined-func-template`` warning when a function template is not instantiated due to being unreachable in modules.
+- Clang now emits a ``-Wignored-base-class-qualifiers`` diagnostic when a base class includes cv-qualifiers.
+
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index b9f08d96151c9..a8b9f9c9a6971 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -497,6 +497,7 @@ def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
def IgnoredGCH : DiagGroup<"ignored-gch">;
def IgnoredReferenceQualifiers : DiagGroup<"ignored-reference-qualifiers">;
def IgnoredQualifiers : DiagGroup<"ignored-qualifiers", [IgnoredReferenceQualifiers]>;
+def IgnoredBaseClassQualifiers : DiagGroup<"ignored-base-class-qualifiers", [IgnoredReferenceQualifiers]>;
def : DiagGroup<"import">;
def GNUIncludeNext : DiagGroup<"gnu-include-next">;
def IncompatibleMSStruct : DiagGroup<"incompatible-ms-struct">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1536a3b8c920a..720570fed2af5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -492,7 +492,7 @@ def warn_qual_return_type : Warning<
InGroup<IgnoredQualifiers>, DefaultIgnore;
def warn_qual_base_type : Warning<
"'%0' qualifier%s1 on base class type %2 %plural{1:has|:have}1 no effect">,
- InGroup<IgnoredQualifiers>, DefaultIgnore;
+ InGroup<IgnoredBaseClassQualifiers>, DefaultIgnore;
def warn_deprecated_redundant_constexpr_static_def : Warning<
"out-of-line definition of constexpr static data member is redundant "
diff --git a/clang/test/SemaCXX/warn-base-type-qualifiers.cpp b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
index 7c775a552dd88..2879c8dda5e97 100644
--- a/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
+++ b/clang/test/SemaCXX/warn-base-type-qualifiers.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -std=c++11 -Wignored-qualifiers -verify
+// RUN: %clang_cc1 %s -std=c++11 -Wignored-base-class-qualifiers -verify
template <typename T> struct add_const {
using type = const T;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy when Aaron is happy with commit message/etc. THOUGH we should do Fixes: #<BUG NUMBER>
in it so it auto-closes the bug.
I suspect we'll have to merge this for you, so if you notice CI has passed, feel free to ping us and we'll do it.
I suggest backporting to the 20 release. Wdyt? (If we decide so, the release notes would go into 20 instead of main) |
Happy to adjust this @MagentaTreehouse for LLVM 20 - what would that require? @erichkeane is this ok to merge (assuming I make the changes for the above - the CI has passed) |
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Thanks for the review @AaronBallman , I've updated the PR from your comments and the CI has passed - is this good to merge now? |
@lyledean1 I think the process is that the release notes are left unchanged in this PR; after it is merged we add this to LLVM 20.X Release milestone, open a backport PR by cherry-picking the commit (Example), and add changes to the release notes there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I don't think this qualifies for backporting. It's not fixing a bug, and it's technically an ABI break because we generate enumerators for the diagnostic IDs and this will shift the numbers around. |
Once you resolve the merge conflicts so precommit CI comes back green, I can land the changes |
@@ -298,6 +298,8 @@ Improvements to Clang's diagnostics | |||
|
|||
- Improve the ``-Wundefined-func-template`` warning when a function template is not instantiated due to being unreachable in modules. | |||
|
|||
- Split diagnosing base class qualifiers from the ``-Wignored-Qualifiers`` diagnostic group into a new ``-Wignored-base-class-qualifiers`` diagnostic group (which is grouped under ``-Wignored-qualifiers``). Fixes #GH131935. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "is grouped under" relationship is the wrong way around. Should it be "controls"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the wording is sufficient. No need to change IMO.
It isn't clear what the merge conflicts are (github won't tell me for some reason?) but those need fixing before we can merge this. |
It was on the release notes, that's fixed now |
CI seems to be failing with the message But haven't changed anything around this? |
Precommit CI failure on Linux appears to be unrelated, so landing the changes (I'll watch the bots in case it was related somehow). |
@lyledean1 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Split diagnosing base class qualifiers from the
-Wignored-Qualifiers
diagnostic group into a new-Wignored-base-class-qualifiers
diagnostic group (which is grouped under-Wignored-qualifiers
).Fixes: #131935