[clang-tools-extra] [clang-tidy] Change IgnoreExternC default to true in modernize-use-using (PR #199189)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 22 04:55:55 PDT 2026
https://github.com/voyager-jhk updated https://github.com/llvm/llvm-project/pull/199189
>From 09c36db9d777eb80d5d25dfd9fcd734b4f20c1f6 Mon Sep 17 00:00:00 2001
From: voyager-jhk <voyager.lpq at gmail.com>
Date: Fri, 22 May 2026 16:57:44 +0800
Subject: [PATCH] [clang-tidy] Change IgnoreExternC default to true in
modernize-use-using
This prevents generating invalid C code in mixed-language headers by leaving
`typedef` declarations inside `extern "C"` blocks intact by default.
Fixes #141394
---
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp | 2 +-
clang-tools-extra/docs/ReleaseNotes.rst | 6 ++++++
.../docs/clang-tidy/checks/modernize/use-using.rst | 2 +-
.../checkers/modernize/use-using-ignore-extern-c.cpp | 6 ++++--
.../test/clang-tidy/checkers/modernize/use-using.cpp | 2 --
5 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index 327fe02735468..cbb3babe9d472 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -235,7 +235,7 @@ static constexpr StringRef DeclStmtName = "decl-stmt";
UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.get("IgnoreMacros", true)),
- IgnoreExternC(Options.get("IgnoreExternC", false)) {}
+ IgnoreExternC(Options.get("IgnoreExternC", true)) {}
void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index e60800fd913d1..81ce844dd3843 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -49,6 +49,10 @@ Major New Features
Potentially Breaking Changes
----------------------------
+- The :doc:`modernize-use-using <clang-tidy/checks/modernize/use-using>` check
+ now sets the ``IgnoreExternC`` option to ``true`` by default. The check will
+ no longer transform ``typedef``\ s within ``extern "C"`` blocks.
+
- Deprecated the :program:`clang-tidy` check :doc:`performance-faster-string-find
<clang-tidy/checks/performance/faster-string-find>`. It has been renamed to
:doc:`performance-prefer-single-char-overloads
@@ -580,6 +584,8 @@ Changes in existing checks
- Preserve inline comment blocks that appear between the ``typedef``'s parts.
+ - The ``IgnoreExternC`` option is now enabled by default.
+
- Improved :doc:`performance-enum-size
<clang-tidy/checks/performance/enum-size>` check:
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index 9eedf20cb9723..82704fbbfedb0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -49,4 +49,4 @@ Options
.. option:: IgnoreExternC
If set to `true`, the check will not give warning inside ``extern "C"``
- scope. Default is `false`
+ scope. Default is `true`.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp
index 6a845a0bcc350..f45f37bcfe56f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp
@@ -1,9 +1,11 @@
-// RUN: %check_clang_tidy %s modernize-use-using %t -- -config="{CheckOptions: {modernize-use-using.IgnoreExternC: true}}" -- -I %S/Input/use-using/
+// RUN: %check_clang_tidy %s modernize-use-using %t -- -config="{CheckOptions: {modernize-use-using.IgnoreExternC: false}}" -- -I %S/Input/use-using/
// Some Header
extern "C" {
typedef int NewInt;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
+// CHECK-FIXES: using NewInt = int;
}
extern "C++" {
@@ -11,4 +13,4 @@ extern "C++" {
typedef int InExternCPP;
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
// CHECK-FIXES: using InExternCPP = int;
-}
+}
\ No newline at end of file
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 232dd33f35f37..36dc93faca461 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -330,8 +330,6 @@ typedef class ISSUE_67529_1 *ISSUE_67529;
extern "C" {
typedef int InExternC;
-// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
-// CHECK-FIXES: using InExternC = int;
}
More information about the cfe-commits
mailing list