[all-commits] [llvm/llvm-project] 82ddae: [clang-tidy] RenamerClangTidy now renames dependen...

Nathan James via All-commits all-commits at lists.llvm.org
Sat May 9 08:22:08 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 82ddae061b4ba11895756004d559160cbd519fff
      https://github.com/llvm/llvm-project/commit/82ddae061b4ba11895756004d559160cbd519fff
  Author: Nathan James <n.james93 at hotmail.co.uk>
  Date:   2020-05-09 (Sat, 09 May 2020)

  Changed paths:
    M clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
    M clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
    M clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp
    M clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.h
    M clang-tools-extra/docs/ReleaseNotes.rst
    M clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
    M clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-member-decl-usage.cpp

  Log Message:
  -----------
  [clang-tidy] RenamerClangTidy now renames dependent member expr when the member can be resolved

Summary:
Sometimes in templated code Member references are reported as `DependentScopeMemberExpr` because that's what the standard dictates, however in many trivial cases it is easy to resolve the reference to its actual Member.
Take this code:
```
template<typename T>
class A{
  int value;
  A& operator=(const A& Other){
    value = Other.value;
    this->value = Other.value;
    return *this;
  }
};
```
When ran with `clang-tidy file.cpp -checks=readability-identifier-naming --config="{CheckOptions: [{key: readability-identifier-naming.MemberPrefix, value: m_}]}" -fix`
Current behaviour:
```
template<typename T>
class A{
  int m_value;
  A& operator=(const A& Other){
    m_value = Other.value;
    this->value = Other.value;
    return *this;
  }
};
```
As `this->value` and `Other.value` are Dependent they are ignored when creating the fix-its, however this can easily be resolved.
Proposed behaviour:
```
template<typename T>
class A{
  int m_value;
  A& operator=(const A& Other){
    m_value = Other.m_value;
    this->m_value = Other.m_value;
    return *this;
  }
};
```

Reviewers: aaron.ballman, JonasToth, alexfh, hokein, gribozavr2

Reviewed By: aaron.ballman

Subscribers: merge_guards_bot, xazax.hun, cfe-commits

Tags: #clang, #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D73052




More information about the All-commits mailing list