[PATCH] D140434: readability-const-return-type: don't diagnose a template function returning T, even if sometimes instantiated with e.g. T = const int.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 23 14:08:53 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG9a11b23c0238: readability-const-return-type: don't diagnose a template function returning T… (authored by suertreus, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140434/new/

https://reviews.llvm.org/D140434

Files:
  clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/const-return-type.cpp
@@ -340,3 +340,18 @@
 __typeof__(const int) n21() {
   return 21;
 }
+
+template <typename T>
+struct n25 {
+  T foo() const { return 2; }
+};
+template struct n25<const int>;
+
+template <typename T>
+struct p41 {
+  const T foo() const { return 2; }
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: return type 'const
+  // CHECK-MESSAGES: [[@LINE-2]]:3: warning: return type 'const
+  // CHECK-FIXES: T foo() const { return 2; }
+};
+template struct p41<int>;
Index: clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/ConstReturnTypeCheck.cpp
@@ -110,9 +110,10 @@
 void ConstReturnTypeCheck::registerMatchers(MatchFinder *Finder) {
   // Find all function definitions for which the return types are `const`
   // qualified, ignoring decltype types.
-  auto NonLocalConstType = qualType(
-      unless(isLocalConstQualified()),
-      anyOf(decltypeType(), autoType(), isTypeOfType(), isTypeOfExprType()));
+  auto NonLocalConstType =
+      qualType(unless(isLocalConstQualified()),
+               anyOf(decltypeType(), autoType(), isTypeOfType(),
+                     isTypeOfExprType(), substTemplateTypeParmType()));
   Finder->addMatcher(
       functionDecl(
           returns(allOf(isConstQualified(), unless(NonLocalConstType))),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140434.491507.patch
Type: text/x-patch
Size: 1752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230123/605e7754/attachment-0001.bin>


More information about the cfe-commits mailing list