diff --git a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp index cde631e0aa7d..0fd7e771250e 100644 --- a/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp @@ -24,9 +24,9 @@ void UnconventionalAssignOperatorCheck::registerMatchers( if (!getLangOpts().CPlusPlus) return; - const auto HasGoodReturnType = cxxMethodDecl(returns( - lValueReferenceType(pointee(unless(isConstQualified()), - hasDeclaration(equalsBoundNode("class")))))); + const auto HasGoodReturnType = cxxMethodDecl(returns(lValueReferenceType( + pointee(unless(isConstQualified()), + anyOf(autoType(), hasDeclaration(equalsBoundNode("class"))))))); const auto IsSelf = qualType( anyOf(hasDeclaration(equalsBoundNode("class")), diff --git a/clang-tools-extra/test/clang-tidy/misc-unconventional-assign-operator-cxx17.cpp b/clang-tools-extra/test/clang-tidy/misc-unconventional-assign-operator-cxx17.cpp new file mode 100644 index 000000000000..ba1a685842ef --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/misc-unconventional-assign-operator-cxx17.cpp @@ -0,0 +1,12 @@ +// RUN: %check_clang_tidy %s misc-unconventional-assign-operator %t -- -- -std=c++17 -fno-delayed-template-parsing + +struct BadModifier { + BadModifier& operator=(const BadModifier&) const; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should not be marked 'const' +}; + +struct PR35468 { + template auto &operator=(const T &) { + return *this; + } +};