https://github.com/voyager-jhk updated https://github.com/llvm/llvm-project/pull/199189
>From 2a465c1ef7ab4ed081a23cbbb6831ac1eedbba8e Mon Sep 17 00:00:00 2001 From: voyager-jhk <[email protected]> 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 | 4 +++- .../test/clang-tidy/checkers/modernize/use-using.cpp | 2 -- 5 files changed, 11 insertions(+), 5 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..b3a2e89ac90c6 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 set to `true` 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..ac7c767c610e3 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++" { 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; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
