Index: clang-tidy/readability/IdentifierNamingCheck.cpp =================================================================== --- clang-tidy/readability/IdentifierNamingCheck.cpp +++ clang-tidy/readability/IdentifierNamingCheck.cpp @@ -262,6 +262,11 @@ else Matches = false; + // Ensure the name doesn't have any extra underscores beyond those specified + // in the prefix and suffix. + if (Name.startswith("_") || Name.endswith("_")) + Matches = false; + if (Style.Case && !Matchers[static_cast(*Style.Case)].match(Name)) Matches = false; @@ -367,10 +372,12 @@ static std::string fixupWithStyle(StringRef Name, const IdentifierNamingCheck::NamingStyle &Style) { - return Style.Prefix + - fixupWithCase(Name, Style.Case.getValueOr( - IdentifierNamingCheck::CaseType::CT_AnyCase)) + - Style.Suffix; + const std::string Fixed = fixupWithCase( + Name, Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase)); + StringRef Mid = StringRef(Fixed).trim("_"); + if (Mid.empty()) + Mid = "_"; + return (Style.Prefix + Mid + Style.Suffix).str(); } static StyleKind findStyleKind( Index: test/clang-tidy/readability-identifier-naming.cpp =================================================================== --- test/clang-tidy/readability-identifier-naming.cpp +++ test/clang-tidy/readability-identifier-naming.cpp @@ -175,6 +175,9 @@ int member2 = 2; // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member 'member2' // CHECK-FIXES: {{^}} int __member2 = 2;{{$}} + int _memberWithExtraUnderscores_ = 42; +// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: invalid case style for private member '_memberWithExtraUnderscores_' +// CHECK-FIXES: {{^}} int __memberWithExtraUnderscores = 42;{{$}} private: int private_member = 3;