[PATCH] D90129: Source location for -Wignored-qualifiers on lambda trailing return type

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 25 18:44:52 PDT 2020


aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aaronpuchert requested review of this revision.

We don't have a source location for trailing return types at the moment,
and the current fallback (the identifier location) doesn't work for
lambdas. So instead we take the location of the right paranthesis, which
seems as close to the trailing return type as we can get.

Fixes PR47732.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90129

Files:
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/return.cpp


Index: clang/test/SemaCXX/return.cpp
===================================================================
--- clang/test/SemaCXX/return.cpp
+++ clang/test/SemaCXX/return.cpp
@@ -65,6 +65,10 @@
     trailing_return_type() -> // expected-warning {{'const' type qualifier on return type has no effect}}
     const int;
 
+auto trailing_return_type_lambda =
+    [](const int &x) -> // expected-warning {{'const' type qualifier on return type has no effect}}
+    const int { return x; };
+
 const int ret_array()[4]; // expected-error {{cannot return array}}
 }
 
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3084,12 +3084,16 @@
 static void diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy,
                                                   Declarator &D,
                                                   unsigned FunctionChunkIndex) {
-  if (D.getTypeObject(FunctionChunkIndex).Fun.hasTrailingReturnType()) {
+  const DeclaratorChunk::FunctionTypeInfo &FTI =
+      D.getTypeObject(FunctionChunkIndex).Fun;
+  if (FTI.hasTrailingReturnType()) {
     // FIXME: TypeSourceInfo doesn't preserve location information for
     // qualifiers.
+    SourceLocation Loc = D.getIdentifierLoc();
+    if (Loc.isInvalid())
+      Loc = FTI.getRParenLoc();
     S.diagnoseIgnoredQualifiers(diag::warn_qual_return_type,
-                                RetTy.getLocalCVRQualifiers(),
-                                D.getIdentifierLoc());
+                                RetTy.getLocalCVRQualifiers(), Loc);
     return;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90129.300565.patch
Type: text/x-patch
Size: 1656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/51bb8434/attachment.bin>


More information about the cfe-commits mailing list