aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYounan Zhang <zyn7109@gmail.com>2025-07-30 14:07:06 +0800
committerGitHub <noreply@github.com>2025-07-30 14:07:06 +0800
commita9d491b17f4f0a131f68a5dbdac8d34c7c8427db (patch)
tree5ce1a2460298499dc77172a09308f445b83cc88a
parent8f187c74b3ad77ef8a15bc3d2d718ccd88edb873 (diff)
downloadllvm-a9d491b17f4f0a131f68a5dbdac8d34c7c8427db.zip
llvm-a9d491b17f4f0a131f68a5dbdac8d34c7c8427db.tar.gz
llvm-a9d491b17f4f0a131f68a5dbdac8d34c7c8427db.tar.bz2
[Clang] Don't allow implicit this access when checking function constraints (#151276)
We allowed implicit this access when checking associated constraints after CWG2369. As a result, some of the invalid function call expressions were not properly SFINAE'ed out and ended up as hard errors at evaluation time. We tried fixing that by mucking around the CurContext, but that spawned additional breakages and I think it's probably safe to revert to the previous behavior to avoid churns. Though there is CWG2589, which justifies the previous change, it's not what we're pursuing now. Fixes https://github.com/llvm/llvm-project/issues/151271 Fixes https://github.com/llvm/llvm-project/issues/145505
-rw-r--r--clang/lib/Sema/SemaConcept.cpp4
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp2
-rw-r--r--clang/test/SemaTemplate/concepts.cpp34
3 files changed, 17 insertions, 23 deletions
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 044cf5c..da85959 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1105,10 +1105,6 @@ static bool CheckFunctionConstraintsWithoutInstantiation(
}
Sema::ContextRAII SavedContext(SemaRef, FD);
- std::optional<Sema::CXXThisScopeRAII> ThisScope;
- if (auto *Method = dyn_cast<CXXMethodDecl>(FD))
- ThisScope.emplace(SemaRef, /*Record=*/Method->getParent(),
- /*ThisQuals=*/Method->getMethodQualifiers());
return SemaRef.CheckConstraintSatisfaction(
Template, TemplateAC, MLTAL, PointOfInstantiation, Satisfaction);
}
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 698d127..21fed2e 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4749,8 +4749,6 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
EnterExpressionEvaluationContext EECtx{
*this, ExpressionEvaluationContext::Unevaluated, CSD};
- ContextRAII CurContext(*this, CSD->getDeclContext(),
- /*NewThisContext=*/false);
if (!AreArgsDependent &&
CheckConstraintSatisfaction(
NamedConcept, AssociatedConstraint(NamedConcept->getConstraintExpr()),
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 663bc98..d63ad01 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1228,26 +1228,26 @@ template <KnownKind T> struct KnownType {
}
-namespace GH115838 {
+namespace CWG2369_Regression_2 {
-template<typename T> concept has_x = requires(T t) {{ t.x };};
-
-class Publ { public: int x = 0; };
-class Priv { private: int x = 0; };
-class Prot { protected: int x = 0; };
-class Same { protected: int x = 0; };
-
-template<typename T> class D;
-template<typename T> requires ( has_x<T>) class D<T>: public T { public: static constexpr bool has = 1; };
-template<typename T> requires (!has_x<T>) class D<T>: public T { public: static constexpr bool has = 0; };
+template <typename T>
+concept HasFastPropertyForAttribute =
+ requires(T element, int name) { element.propertyForAttribute(name); };
+
+template <typename OwnerType>
+struct SVGPropertyOwnerRegistry {
+ static int fastAnimatedPropertyLookup() {
+ static_assert (HasFastPropertyForAttribute<OwnerType>);
+ return 1;
+ }
+};
-// "Same" is identical to "Prot" but queried before used.
-static_assert(!has_x<Same>, "Protected should be invisible.");
-static_assert(!D<Same>::has, "Protected should be invisible.");
+class SVGCircleElement {
+ friend SVGPropertyOwnerRegistry<SVGCircleElement>;
+ void propertyForAttribute(int);
+};
-static_assert( D<Publ>::has, "Public should be visible.");
-static_assert(!D<Priv>::has, "Private should be invisible.");
-static_assert(!D<Prot>::has, "Protected should be invisible.");
+int i = SVGPropertyOwnerRegistry<SVGCircleElement>::fastAnimatedPropertyLookup();
}