-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check #143550
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
Merged
vbvictor
merged 3 commits into
llvm:main
from
vbvictor:ignore-macros-special-member-functions
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-macros.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// RUN: %check_clang_tidy %s cppcoreguidelines-special-member-functions %t -- -config="{CheckOptions: {cppcoreguidelines-special-member-functions.IgnoreMacros: false}}" -- | ||
|
||
class DefinesDestructor { | ||
~DefinesDestructor(); | ||
}; | ||
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDestructor' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] | ||
|
||
class DefinesDefaultedDestructor { | ||
~DefinesDefaultedDestructor() = default; | ||
}; | ||
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesDefaultedDestructor' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] | ||
|
||
class DefinesCopyConstructor { | ||
DefinesCopyConstructor(const DefinesCopyConstructor &); | ||
}; | ||
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'DefinesCopyConstructor' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions] | ||
|
||
class DefinesNothing { | ||
}; | ||
|
||
class DefinesEverything { | ||
DefinesEverything(const DefinesEverything &); | ||
DefinesEverything &operator=(const DefinesEverything &); | ||
DefinesEverything(DefinesEverything &&); | ||
DefinesEverything &operator=(DefinesEverything &&); | ||
~DefinesEverything(); | ||
}; | ||
|
||
#define DEFINE_DESTRUCTOR_ONLY(ClassName) \ | ||
class ClassName { \ | ||
~ClassName(); \ | ||
}; | ||
|
||
#define DEFINE_COPY_CTOR_ONLY(ClassName) \ | ||
class ClassName { \ | ||
ClassName(const ClassName &); \ | ||
}; | ||
|
||
#define DEFINE_CLASS_WITH_DTOR(ClassName) \ | ||
class ClassName { \ | ||
~ClassName(); \ | ||
}; | ||
|
||
DEFINE_DESTRUCTOR_ONLY(MacroDefinedClass1) | ||
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: class 'MacroDefinedClass1' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator | ||
DEFINE_COPY_CTOR_ONLY(MacroDefinedClass2) | ||
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: class 'MacroDefinedClass2' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator | ||
DEFINE_CLASS_WITH_DTOR(MacroDefinedClass3) | ||
// CHECK-MESSAGES: [[@LINE-1]]:24: warning: class 'MacroDefinedClass3' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator | ||
|
||
// Test partial macro expansion | ||
#define CLASS_NAME MacroNamedClass | ||
class CLASS_NAME { | ||
~MacroNamedClass(); | ||
}; | ||
// CHECK-MESSAGES: [[@LINE-3]]:7: warning: class 'MacroNamedClass' defines a destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
(For another commit) This comes up often, maybe we can create an AST matcher for this that can be reused?
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.
Yes, I was thinking lately about it.
I've seen some matchers use only
Node.getBeginLoc().isMacroID()
others useNode.getBeginLoc().isMacroID() && Node.getEndLoc().isMacroID()
so we need to decide on the wanted behavior.I guess we should place both
Begin
andEnd
inside a macro