[clang] 0c67cfd - [Concepts] Add missing CXXThisScope to function template constraint substitution
Saar Raz via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 4 14:55:26 PST 2020
Author: Saar Raz
Date: 2020-02-05T00:55:14+02:00
New Revision: 0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768
URL: https://github.com/llvm/llvm-project/commit/0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768
DIFF: https://github.com/llvm/llvm-project/commit/0c67cfdb114b4c2f5c7ec374cf12118c7fa9d768.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)
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..2a42e2410fc3 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>
+ void foo() requires (*this, true) { }
+ void goo() requires (*this, true) { }
+};
+
+static_assert((S4<int>{}.foo<int>(), S4<int>{}.goo(), true));
More information about the cfe-commits
mailing list