[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor closed 
https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Baranov Victor via cfe-commits

vbvictor wrote:

> I meant macros defined in system headers, but with expansions in user code.

Make sense, I suppose we should make for that and potentially implement such 
logic in more checks.

I think we can land this as is for now

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

> > Actually, the cxxRecordDecl might not be in a macro, but the special member 
> > functions are.
> 
> The checker doc states:
> `The check finds classes where some but not all of the special member 
> functions are defined.`
> I think we only need to ignore if the whole class expands from macro. If not, 
> I don't see a reason why a user can't provided needed members.

Good point 

> > I'd prefer to see a warning for expansions of macros defined inside the 
> > code base
> 
> I think we could just limit the scope of the whole check by 
> `unless(isExpansionInSystemHeader())`.
> There was some work by [carlosgalvezp](https://github.com/carlosgalvezp) to 
> ignore system headers in all checks by default so maybe this addition will 
> become obsolete soon.

Yeah, this was just a thought. But that work would not be for this (I think). I 
meant macros defined in system headers, but with expansions in user code.

> > I'm +- on the default
> 
> FYI there is a total of 22 checks that use `IgnoreMacros` option, 17 of them 
> have `true` by default and 5 have `false`
> 

Then let's stay with what it is now (true). For things like goto, it makes IMO 
sense to use false because goto is a really bad pattern.


https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/143550

>From 897ef525a85345811ed8d3bc4da8d2886d05dfe7 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Tue, 10 Jun 2025 18:12:35 +0300
Subject: [PATCH 1/3] [clang-tidy] add 'IgnoreMarcos' option to
 'special-member-functions' check

---
 .../SpecialMemberFunctionsCheck.cpp   | 15 -
 .../SpecialMemberFunctionsCheck.h |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 +++
 .../special-member-functions.rst  |  5 ++
 .../special-member-functions-macros.cpp   | 57 +++
 .../special-member-functions.cpp  | 26 +
 6 files changed, 109 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-macros.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index 0de143dbb1b89..0b6b8d9c97135 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -18,6 +18,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER(CXXRecordDecl, isInMacro) {
+  return Node.getBeginLoc().isMacroID() && Node.getEndLoc().isMacroID();
+}
+} // namespace
+
 SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), AllowMissingMoveFunctions(Options.get(
@@ -26,7 +32,8 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
   AllowMissingMoveFunctionsWhenCopyIsDeleted(
   Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", false)),
   AllowImplicitlyDeletedCopyOrMove(
-  Options.get("AllowImplicitlyDeletedCopyOrMove", false)) {}
+  Options.get("AllowImplicitlyDeletedCopyOrMove", false)),
+  IgnoreMacros(Options.get("IgnoreMacros", true)) {}
 
 void SpecialMemberFunctionsCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -36,6 +43,7 @@ void SpecialMemberFunctionsCheck::storeOptions(
 AllowMissingMoveFunctionsWhenCopyIsDeleted);
   Options.store(Opts, "AllowImplicitlyDeletedCopyOrMove",
 AllowImplicitlyDeletedCopyOrMove);
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
 std::optional
@@ -45,11 +53,12 @@ SpecialMemberFunctionsCheck::getCheckTraversalKind() const {
 }
 
 void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
-  auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const ast_matchers::internal::Matcher Anything = anything();
 
   Finder->addMatcher(
   cxxRecordDecl(
-  unless(isImplicit()),
+  unless(isImplicit()), IgnoreMacros ? unless(isInMacro()) : Anything,
   eachOf(has(cxxDestructorDecl(unless(isImplicit())).bind("dtor")),
  has(cxxConstructorDecl(isCopyConstructor(),
 IsNotImplicitOrDeleted)
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
index dee01cb5a9fdd..c18ed7db055ba 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -69,6 +69,7 @@ class SpecialMemberFunctionsCheck : public ClangTidyCheck {
   const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
   const bool AllowImplicitlyDeletedCopyOrMove;
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
+  const bool IgnoreMacros;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a802b5fc6699f..d42f72cbcea63 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -207,6 +207,10 @@ Changes in existing checks
   ` check by adding the option
   `IgnoreMacros` to ignore ``goto`` labels defined in macros.
 
+- Improved :doc:`cppcoreguidelines-special-member-functions
+  ` check by
+  adding the option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`google-readability-namespace-comments
   ` check by adding
   the option `AllowOmittingNamespaceComments` to accept if a namespace comment
@@ -216,6 +220,10 @@ Changes in existing checks
   ` check by adding the option
   `IgnoreMacros` to ignore ``goto`` labels defined in macros.
 
+- Improved :doc:`hicpp-special-member-functions
+  ` check by adding the
+  option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`llvm-namespace-comment
   ` check by addi

[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Baranov Victor via cfe-commits


@@ -18,6 +18,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER(CXXRecordDecl, isInMacro) {

vbvictor wrote:

Yes, I was thinking lately about it.
I've seen some matchers use only `Node.getBeginLoc().isMacroID()` others use 
`Node.getBeginLoc().isMacroID() && Node.getEndLoc().isMacroID()` so we need to 
decide on the wanted behavior.
I guess we should place both `Begin` and `End` inside a macro 

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-23 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM, don't have strong opinions on the default.

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-22 Thread Carlos Galvez via cfe-commits


@@ -18,6 +18,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER(CXXRecordDecl, isInMacro) {

carlosgalvezp wrote:

(For another commit) This comes up often, maybe we can create an AST matcher 
for this that can be reused?

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Baranov Victor via cfe-commits

vbvictor wrote:

> Actually, the cxxRecordDecl might not be in a macro, but the special member 
> functions are.

The checker doc states:
`The check finds classes where some but not all of the special member functions 
are defined.`
I think we only need to ignore if the whole class expands from macro. If not, I 
don't see a reason why a user can't provided needed members.

> I'd prefer to see a warning for expansions of macros defined inside the code 
> base

I think we could just limit the scope of the whole check by 
`unless(isExpansionInSystemHeader())`.
There was some work by [carlosgalvezp](https://github.com/carlosgalvezp) to 
ignore system headers in all checks by default so maybe this addition will 
become obsolete soon.

> I'm +- on the default

FYI there are total of 22 checks that use `IgnoreMacros` option, 17 of them 
have `true` by default and 5 have `false`


https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Julian Schmidt via cfe-commits


@@ -45,11 +53,12 @@ SpecialMemberFunctionsCheck::getCheckTraversalKind() const {
 }
 
 void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
-  auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const ast_matchers::internal::Matcher Anything = anything();

5chmidti wrote:

nit: no need to declare this variable, just use anything() diectly

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti deleted 
https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Julian Schmidt via cfe-commits

5chmidti wrote:

Actually, the cxxRecordDecl might not be in a macro, but the special member 
functions are.
E.g.:
``` ` ` cpp
#define DEF_COPY(name) \
name(const name&) = default; \
name& operator=(const name&) = default;
` ` ` 

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti edited 
https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-21 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

LGTM but I'm +- on the default

Let's see if others have a stronger opinion on the default

---

Not directly part of this, but:
I'd prefer to see a warning for expansions of macros defined inside the code 
base, but not from macros defined outside of it. (E.g. MY_CLASS vs gtest macros)

https://github.com/llvm/llvm-project/pull/143550
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-10 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/143550

None

>From 229141e0e7c8b81f3522cea0e559660822265745 Mon Sep 17 00:00:00 2001
From: Victor Baranov 
Date: Tue, 10 Jun 2025 18:12:35 +0300
Subject: [PATCH 1/3] [clang-tidy] add 'IgnoreMarcos' option to
 'special-member-functions' check

---
 .../SpecialMemberFunctionsCheck.cpp   | 15 -
 .../SpecialMemberFunctionsCheck.h |  1 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  8 +++
 .../special-member-functions.rst  |  5 ++
 .../special-member-functions-macros.cpp   | 57 +++
 .../special-member-functions.cpp  | 26 +
 6 files changed, 109 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-macros.cpp

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index 0de143dbb1b89..0b6b8d9c97135 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -18,6 +18,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER(CXXRecordDecl, isInMacro) {
+  return Node.getBeginLoc().isMacroID() && Node.getEndLoc().isMacroID();
+}
+} // namespace
+
 SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), AllowMissingMoveFunctions(Options.get(
@@ -26,7 +32,8 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
   AllowMissingMoveFunctionsWhenCopyIsDeleted(
   Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", false)),
   AllowImplicitlyDeletedCopyOrMove(
-  Options.get("AllowImplicitlyDeletedCopyOrMove", false)) {}
+  Options.get("AllowImplicitlyDeletedCopyOrMove", false)),
+  IgnoreMacros(Options.get("IgnoreMacros", true)) {}
 
 void SpecialMemberFunctionsCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -36,6 +43,7 @@ void SpecialMemberFunctionsCheck::storeOptions(
 AllowMissingMoveFunctionsWhenCopyIsDeleted);
   Options.store(Opts, "AllowImplicitlyDeletedCopyOrMove",
 AllowImplicitlyDeletedCopyOrMove);
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
 std::optional
@@ -45,11 +53,12 @@ SpecialMemberFunctionsCheck::getCheckTraversalKind() const {
 }
 
 void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
-  auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const ast_matchers::internal::Matcher Anything = anything();
 
   Finder->addMatcher(
   cxxRecordDecl(
-  unless(isImplicit()),
+  unless(isImplicit()), IgnoreMacros ? unless(isInMacro()) : Anything,
   eachOf(has(cxxDestructorDecl(unless(isImplicit())).bind("dtor")),
  has(cxxConstructorDecl(isCopyConstructor(),
 IsNotImplicitOrDeleted)
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
index dee01cb5a9fdd..c18ed7db055ba 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -69,6 +69,7 @@ class SpecialMemberFunctionsCheck : public ClangTidyCheck {
   const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
   const bool AllowImplicitlyDeletedCopyOrMove;
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
+  const bool IgnoreMacros;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19ccd1790e757..a79c10ed15a3d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -191,11 +191,19 @@ Changes in existing checks
   ` check by fixing a false positive
   where ``strerror`` was flagged as MT-unsafe.
 
+- Improved :doc:`cppcoreguidelines-special-member-functions
+  ` check by
+  adding the option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`google-readability-namespace-comments
   ` check by adding
   the option `AllowOmittingNamespaceComments` to accept if a namespace comment
   is omitted entirely.
 
+- Improved :doc:`hicpp-special-member-functions
+  ` check by adding the
+  option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`llvm-namespace-comment
   ` check by adding the option
   `AllowOmittingNamespaceComments` to accept if a namespace comment is omitted
diff --git 
a/clang-tools-e

[clang-tools-extra] [clang-tidy] add 'IgnoreMarcos' option to 'special-member-functions' check (PR #143550)

2025-06-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Baranov Victor (vbvictor)


Changes



---
Full diff: https://github.com/llvm/llvm-project/pull/143550.diff


6 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp 
(+12-3) 
- (modified) 
clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h 
(+1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+8) 
- (modified) 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
 (+5) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-macros.cpp
 (+57) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp
 (+26) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index 0de143dbb1b89..0b6b8d9c97135 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -18,6 +18,12 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
+namespace {
+AST_MATCHER(CXXRecordDecl, isInMacro) {
+  return Node.getBeginLoc().isMacroID() && Node.getEndLoc().isMacroID();
+}
+} // namespace
+
 SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
 StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context), AllowMissingMoveFunctions(Options.get(
@@ -26,7 +32,8 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
   AllowMissingMoveFunctionsWhenCopyIsDeleted(
   Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", false)),
   AllowImplicitlyDeletedCopyOrMove(
-  Options.get("AllowImplicitlyDeletedCopyOrMove", false)) {}
+  Options.get("AllowImplicitlyDeletedCopyOrMove", false)),
+  IgnoreMacros(Options.get("IgnoreMacros", true)) {}
 
 void SpecialMemberFunctionsCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -36,6 +43,7 @@ void SpecialMemberFunctionsCheck::storeOptions(
 AllowMissingMoveFunctionsWhenCopyIsDeleted);
   Options.store(Opts, "AllowImplicitlyDeletedCopyOrMove",
 AllowImplicitlyDeletedCopyOrMove);
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
 std::optional
@@ -45,11 +53,12 @@ SpecialMemberFunctionsCheck::getCheckTraversalKind() const {
 }
 
 void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
-  auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+  const ast_matchers::internal::Matcher Anything = anything();
 
   Finder->addMatcher(
   cxxRecordDecl(
-  unless(isImplicit()),
+  unless(isImplicit()), IgnoreMacros ? unless(isInMacro()) : Anything,
   eachOf(has(cxxDestructorDecl(unless(isImplicit())).bind("dtor")),
  has(cxxConstructorDecl(isCopyConstructor(),
 IsNotImplicitOrDeleted)
diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
index dee01cb5a9fdd..c18ed7db055ba 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h
@@ -69,6 +69,7 @@ class SpecialMemberFunctionsCheck : public ClangTidyCheck {
   const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
   const bool AllowImplicitlyDeletedCopyOrMove;
   ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
+  const bool IgnoreMacros;
 };
 
 } // namespace clang::tidy::cppcoreguidelines
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19ccd1790e757..a79c10ed15a3d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -191,11 +191,19 @@ Changes in existing checks
   ` check by fixing a false positive
   where ``strerror`` was flagged as MT-unsafe.
 
+- Improved :doc:`cppcoreguidelines-special-member-functions
+  ` check by
+  adding the option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`google-readability-namespace-comments
   ` check by adding
   the option `AllowOmittingNamespaceComments` to accept if a namespace comment
   is omitted entirely.
 
+- Improved :doc:`hicpp-special-member-functions
+  ` check by adding the
+  option `IgnoreMacros` to ignore classes defined in macros.
+
 - Improved :doc:`llvm-namespace-comment
   ` check by adding the option
   `AllowOmittingNamespaceComments` to accept if a namespace comment is omitted
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines