Skip to content

Commit ffcc0bf

Browse files
committed
[clang-tidy] Rename out-of-line function definitions
Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration.
1 parent e76b257 commit ffcc0bf

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ static const NamedDecl *getFailureForNamedDecl(const NamedDecl *ND) {
123123
if (const auto *Method = dyn_cast<CXXMethodDecl>(ND)) {
124124
if (const CXXMethodDecl *Overridden = getOverrideMethod(Method))
125125
Canonical = cast<NamedDecl>(Overridden->getCanonicalDecl());
126+
else if (const FunctionTemplateDecl *Primary = Method->getPrimaryTemplate())
127+
if (const FunctionDecl *TemplatedDecl = Primary->getTemplatedDecl())
128+
Canonical = cast<NamedDecl>(TemplatedDecl->getCanonicalDecl());
126129

127130
if (Canonical != ND)
128131
return Canonical;

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ Changes in existing checks
343343
<clang-tidy/checks/readability/identifier-naming>` check in `GetConfigPerFile`
344344
mode by resolving symbolic links to header files. Fixed handling of Hungarian
345345
Prefix when configured to `LowerCase`. Added support for renaming designated
346-
initializers. Added support for renaming macro arguments.
346+
initializers. Added support for renaming macro arguments. Fixed renaming
347+
conflicts arising from out-of-line member function template definitions.
347348

348349
- Improved :doc:`readability-implicit-bool-conversion
349350
<clang-tidy/checks/readability/implicit-bool-conversion>` check to provide
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %check_clang_tidy %s readability-identifier-naming %t -std=c++20 \
2+
// RUN: --config='{CheckOptions: { \
3+
// RUN: readability-identifier-naming.MethodCase: CamelCase, \
4+
// RUN: }}'
5+
6+
namespace SomeNamespace {
7+
namespace Inner {
8+
9+
class SomeClass {
10+
public:
11+
template <typename T>
12+
int someMethod();
13+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for method 'someMethod' [readability-identifier-naming]
14+
// CHECK-FIXES: {{^}} int SomeMethod();
15+
};
16+
template <typename T>
17+
int SomeClass::someMethod() {
18+
// CHECK-FIXES: {{^}}int SomeClass::SomeMethod() {
19+
return 5;
20+
}
21+
22+
} // namespace Inner
23+
24+
void someFunc() {
25+
Inner::SomeClass S;
26+
S.someMethod<int>();
27+
// CHECK-FIXES: {{^}} S.SomeMethod<int>();
28+
}
29+
30+
} // namespace SomeNamespace

0 commit comments

Comments
 (0)