-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix: Suppress -Wshadow warnings in headers on macOS (Fixes #20790) #20793
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
base: master
Are you sure you want to change the base?
Fix: Suppress -Wshadow warnings in headers on macOS (Fixes #20790) #20793
Conversation
…ct#20790) Signed-off-by: Aryan Srivastava <your_github_email@example.com>
Test Results 22 files 22 suites 3d 17h 20m 29s ⏱️ Results for commit d6666b8. |
guitargeek
left a comment
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.
Thank you very much! However, I think the warnings only apply to parts of the header files, like the declaration of kBranchAny in TBranch.h, as explained in #20790.
Suppressing the warnings in the full header files is too drastic. The suppression should be local to the declarations where the warnings actually happen.
|
@guitargeek I have updated the PR to apply the suppression only to the specific lines causing shadows, as requested. Note: I have applied this surgical fix to 9 out of the 13 files. I temporarily reverted the other 4 ( |
|
Update: I ran local diagnostics on the 4 reverted files (TApplication.h, TSocket.h, TVirtualX.h, TGFrame.h) using clang++ -std=c++17 -fsyntax-only -Wshadow on macOS. They produced no shadow warnings. It appears the code in these files has changed since the original issue report and they are now clean. I will leave them untouched. This PR is ready for review. |
core/base/inc/TAttMarker.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Thanks for the review. I've updated the PR to address your feedback:
Reverted TInterpreter.h: Removed the unnecessary changes there.
Corrected Placement: Moved all #pragma suppression blocks below the Copyright headers and includes to follow the file structure rules.
Added Documentation: Added inline comments (// FIXME) explaining that the file-wide suppression is needed due to legacy member variable shadowing.
Ready for re-review!
core/base/inc/TSystem.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
core/meta/inc/TClass.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Why is his needed around a comment?
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.
Fixed (applied same pattern as above).
core/meta/inc/TInterpreter.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
math/matrix/inc/TMatrixT.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
math/matrix/inc/TMatrixTSparse.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
math/matrix/inc/TMatrixTSym.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
tree/tree/inc/TBranch.h
Outdated
| #if defined(__clang__) | ||
| #pragma clang diagnostic push | ||
| #pragma clang diagnostic ignored "-Wshadow" | ||
| #elif defined(__GNUC__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif |
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.
Is the file wide setting still needed? For what symbols? (If it is needed, there should be clear inline documentation of why).
SIde note there should be nothing (new) before the copyright notice.
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.
Fixed (applied same pattern as above).
8403b42 to
b412441
Compare
|
maybe it's worth to add the -Wshadow flag to the CI builds that have the -Woverride, so that the current fix stays maintained. |
|
@ferdymercury Apologies for the delay! That’s a great suggestion regarding the CI. However, I’m concerned that enabling -Wshadow globally right now might trigger warnings in older parts of the codebase that I haven't touched, which would block this PR. To keep this manageable, could we merge these fixes first? I’d be happy to open a follow-up PR to investigate enabling -Wshadow in the CI and fixing any remaining regressions separately. |
| #include "Rtypes.h" | ||
|
|
||
| // FIXME: Temporarily suppress -Wshadow file-wide to avoid warnings from | ||
| // legacy member variables shadowing local variables (PR #20793). |
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 the list shadowed variables in this file?
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.
Hi @pcanal ,
In TAttMarker.h, the shadowed variables are the constructor arguments color and style.
I suppressed the warning because these argument names are part of the public API/header. I wasn't sure if renaming them (e.g. to mcolor, mstyle) would affect documentation or bindings. If you confirm it is safe to rename them in the header, I will do so and remove the pragma.
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.
Thanks for the clarification, please provide the same information for all the files where there is still a global setting.
In TAttMarker.h, the shadowed variables are the constructor arguments color and style.
If it is only one function, why is the setting needed to be global to the file rather than around the constructor?
the constructor arguments color and style.
Out of curiosity where are the version that are shadowed declared?
suppressed the warning because these argument names are part of the public API/header. I wasn't sure if renaming them (e.g. to mcolor, mstyle) would affect documentation or bindings.
The names of the arguments are not 'important' and will not affect the binding. You are right that you also need to review the documentation of that/those function(s) to make sure they are updated accordingly.
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.
Thanks for the clarification regarding the bindings. Since renaming the arguments won't affect the public API or bindings, I agree that renaming is the cleaner solution compared to suppressing warnings.
To answer your questions:
Files involved: The files where I had applied the global suppression (which I will now revert in favor of renaming) are TAttMarker.h, TAttLine.h, TAttFill.h, and TAttText.h.
Why global: I originally placed the suppression globally to avoid cluttering the class definitions with #pragma directives inside the header files. However, renaming the arguments eliminates the need for suppression entirely, which is much better.
Where they are shadowed: The shadowing usually occurs when these headers are included in an environment where global variables like color, style, or font are defined (often from system headers, X11 libraries, or user macros).
Plan: I will proceed with renaming the constructor arguments in the header and source files (e.g., color -> markerColor, style -> markerStyle) to resolve the shadowing warnings and remove the global suppressions. I will also ensure the corresponding documentation/comments are updated to match the new argument names.
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wshadow" | ||
| #endif | ||
| enum EMarkerStyle {kDot=1, kPlus, kStar, kCircle=4, kMultiply=5, |
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.
Please document exactly which of the enums constant are the one shadowing existing symbols and list/refer where the shadowed symbols comes from (if known).
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 suppression was intended for the TAttMarker constructor arguments (color and style), not these enums. However, since we established that renaming the arguments is safe, this suppression block is no longer necessary. I will remove it and rename the arguments in the next update
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 is puzzling since you put these guard specifically around this lines and thus it must/might have been related to one of the symbol on that line, isn't it?
Changes or fixes:
This PR suppresses
-Wshadowwarnings in 13 header files when compiling with Clang on macOS.The warnings were caused by local enumerator names (e.g.,
kBranchAny) shadowing global namespace enums. Since these are public API constants, they cannot be easily renamed without breaking backward compatibility.Following the suggestion in the issue, I wrapped the affected code blocks with: