Author: Bernhard Manfred Gruber
Date: 2020-10-03T10:08:44-04:00
New Revision: 07028cd5dbb8417fb41121a7e75290fab00f65fc

URL: 
https://github.com/llvm/llvm-project/commit/07028cd5dbb8417fb41121a7e75290fab00f65fc
DIFF: 
https://github.com/llvm/llvm-project/commit/07028cd5dbb8417fb41121a7e75290fab00f65fc.diff

LOG: modernize-use-trailing-return-type fix for PR44206

Prevent rewrite when an unqualified id in a typedef type collides
with a function argument name. Fixes PR44206.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
    
clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index b66e24d58b2f..ff2f62e6545b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -66,6 +66,10 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor<UnqualNameVisitor> {
                                 ->getName()))
           return false;
         break;
+      case TypeLoc::Typedef:
+        if (VisitUnqualName(
+                TL.getAs<TypedefTypeLoc>().getTypePtr()->getDecl()->getName()))
+          return false;
       default:
         break;
       }

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
index d5087b598f29..d9efc006b22e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-use-trailing-return-type.cpp
@@ -9,10 +9,16 @@ namespace std {
 
     class string;
 
-    class ostream;
+    template <typename T>
+    class basic_ostream;
+
+    using ostream = basic_ostream<char>;
 
     template <typename T>
     auto declval() -> T;
+
+    template <typename... Ts>
+    class tuple;
 }
 
 //
@@ -527,6 +533,10 @@ std::array<int, Size> j6(unsigned Size);
 std::array<decltype(Size), (Size * 2) + 1> j8(unsigned Size);
 // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: use a trailing return type for 
this function [modernize-use-trailing-return-type]
 // CHECK-FIXES: {{^}}std::array<decltype(Size), (Size * 2) + 1> j8(unsigned 
Size);{{$}}
+using std::ostream;
+std::tuple<int, std::string, ostream>& operator<<(ostream& ostream, float i);
+// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: use a trailing return type for 
this function [modernize-use-trailing-return-type]
+// CHECK-FIXES: {{^}}std::tuple<int, std::string, ostream>& 
operator<<(ostream& ostream, float i);{{$}}
 
 class CC {
     int Object;
@@ -552,7 +562,6 @@ Object DD::g() {
 // bug 44206, no rewrite should happen due to collision with parameter name
 //
 
-using std::ostream;
 ostream& operator<<(ostream& ostream, int i);
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use a trailing return type for 
this function [modernize-use-trailing-return-type]
 // CHECK-FIXES: {{^}}ostream& operator<<(ostream& ostream, int i);{{$}}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to