diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/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); } } diff --git a/clang/test/SemaCXX/PR41139.cpp b/clang/test/SemaCXX/PR41139.cpp new file mode 100644 --- /dev/null +++ b/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 +struct S1 { + S1( R(*f)(Args...) ) {} +}; + +int main() { + S1 s1( f1 ); +} diff --git a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp --- a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp +++ b/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 {