george.burgess.iv created this revision. george.burgess.iv added a reviewer: aaron.ballman.
If code is shared between C and C++, converting a `typedef` to a `using` isn't possible. Being more conservative about emitting these lints in `extern "C"` blocks seems like a good compromise to me. https://reviews.llvm.org/D75492 Files: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp @@ -278,3 +278,7 @@ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, eb2 }; +extern "C" { +typedef int Type; +// No messages expected, since this code may be shared verbatim with C. +} Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp @@ -48,6 +48,9 @@ if (StartLoc.isMacroID() && IgnoreMacros) return; + if (MatchedDecl->getDeclContext()->isExternCContext()) + return; + static const char *UseUsingWarning = "use 'using' instead of 'typedef'"; // Warn at StartLoc but do not fix if there is macro or array.
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp +++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp @@ -278,3 +278,7 @@ // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' // CHECK-FIXES: using EnumT2_CheckTypedefImpactFromAnotherFile = enum { ea2, eb2 }; +extern "C" { +typedef int Type; +// No messages expected, since this code may be shared verbatim with C. +} Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp @@ -48,6 +48,9 @@ if (StartLoc.isMacroID() && IgnoreMacros) return; + if (MatchedDecl->getDeclContext()->isExternCContext()) + return; + static const char *UseUsingWarning = "use 'using' instead of 'typedef'"; // Warn at StartLoc but do not fix if there is macro or array.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits