[llvm-branch-commits] [clang] 8f19f98 - [Concepts] Add missing CXXThisScope to function template constraint substitution

Saar Raz via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 4 15:11:24 PST 2020


Author: Saar Raz
Date: 2020-02-05T01:11:08+02:00
New Revision: 8f19f984f296c8ddbb16dc1623e8a4bd6bfed111

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

LOG: [Concepts] Add missing CXXThisScope to function template constraint substitution

We did not have a CXXThisScope around constraint checking of functions and
function template specializations, causing a crash when checking a constraint
that had a 'this' (bug 44689).

Recommit after fixing test.

(cherry picked from commit 6c232441564f8934477e418347bf0c217abb0a00)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 39169664dad5..290e4cbff4fd 100755
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -329,6 +329,13 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
     Satisfaction.IsSatisfied = true;
     return false;
   }
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
+    ThisQuals = Method->getMethodQualifiers();
+    Record = const_cast<CXXRecordDecl *>(Method->getParent());
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   // We substitute with empty arguments in order to rebuild the atomic
   // constraint in a constant-evaluated context.
   // FIXME: Should this be a dedicated TreeTransform?

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 0e1d5fa77c69..7094462e74c9 100755
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4271,7 +4271,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
             Scope, MLTAL))
       return true;
   }
-
+  Qualifiers ThisQuals;
+  CXXRecordDecl *Record = nullptr;
+  if (auto *Method = dyn_cast<CXXMethodDecl>(Decl)) {
+    ThisQuals = Method->getMethodQualifiers();
+    Record = Method->getParent();
+  }
+  CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs,
                                      PointOfInstantiation, Satisfaction);
 }

diff  --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
index 8e9d5bffa906..a4d1b6597201 100644
--- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp
+++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp
@@ -57,4 +57,13 @@ struct S3 {
 	static constexpr void f(Args...) { }
 };
 
-static_assert((S3<int>::f(), true));
\ No newline at end of file
+static_assert((S3<int>::f(), true));
+
+template<typename T>
+struct S4 {
+    template<typename>
+    constexpr void foo() requires (*this, true) { }
+    constexpr void goo() requires (*this, true) { }
+};
+
+static_assert((S4<int>{}.foo<int>(), S4<int>{}.goo(), true));


        


More information about the llvm-branch-commits mailing list