[PATCH] D60055: Check i < FD->getNumParams() before querying

Violet via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 31 23:00:22 PDT 2019


Violet updated this revision to Diff 193045.
Violet added a comment.

a more straightforward testcase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60055

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/PR41139.cpp
  clang/test/SemaCXX/cxx1y-generic-lambdas.cpp


Index: clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
===================================================================
--- clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
+++ clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
@@ -942,6 +942,13 @@
       return 0;
     };
   }(0)(0);
+
+  int y = [](auto outer) {
+    return [](auto inner) {
+      using T = int(decltype(outer), decltype(inner));
+      return 0;
+    };
+  }(0)(0);
 }
 
 namespace PR23716 {
Index: clang/test/SemaCXX/PR41139.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/PR41139.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s
+
+// expected-no-diagnostics
+
+int f1( unsigned ) { return 0; }
+
+template <class R, class... Args>
+struct S1 {
+    S1( R(*f)(Args...) ) {}
+};
+
+int main() {
+    S1 s1( f1 );
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2892,7 +2892,7 @@
       unsigned i = PV->getFunctionScopeIndex();
       // This parameter might be from a freestanding function type within the
       // function and isn't necessarily referring to one of FD's parameters.
-      if (FD->getParamDecl(i) == PV)
+      if (i < FD->getNumParams() && FD->getParamDecl(i) == PV)
         return FD->getCanonicalDecl()->getParamDecl(i);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60055.193045.patch
Type: text/x-patch
Size: 1479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190401/7455ace6/attachment.bin>


More information about the cfe-commits mailing list