[clang] c2a250e - [Concepts] Fix bug when referencing function parameters in instantiated function template requires clause

Saar Raz via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 22 10:44:20 PST 2020


Author: Saar Raz
Date: 2020-01-22T20:43:38+02:00
New Revision: c2a250e1c43c05925fe040dc9624403af7879453

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

LOG: [Concepts] Fix bug when referencing function parameters in instantiated function template requires clause

Fixes bug #44613 - incorrect instantiated parameters were being added when checking instantiated function constraints

Added: 
    

Modified: 
    clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
    clang/test/SemaTemplate/instantiate-requires-clause.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2f2c06bb72de..8fd7491c45e3 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4252,9 +4252,9 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
         MLTAL.getInnermost(), SourceRange());
     if (Inst.isInvalid())
       return true;
-    if (addInstantiatedParametersToScope(*this, Decl,
-                                        Decl->getTemplateInstantiationPattern(),
-                                         Scope, MLTAL))
+    if (addInstantiatedParametersToScope(
+            *this, Decl, Decl->getPrimaryTemplate()->getTemplatedDecl(),
+            Scope, MLTAL))
       return true;
   }
 

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index f36396b98db7..04b595717e6d 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -29,3 +29,13 @@ using f31 = decltype(f3('a'));
 using f32 = decltype(f3(1, 'b'));
 using f33 = decltype(f3(1, 'b', 2));
 // expected-error at -1 {{no matching function for call to 'f3'}}
+
+template<typename T>
+struct S {
+	template<typename U>
+	static constexpr auto f(U const index) requires(index, true) {
+		return true;
+	}
+};
+
+static_assert(S<void>::f(1));


        


More information about the cfe-commits mailing list