Skip to content

Commit a9d491b

Browse files
authored
[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 #151271 Fixes #145505
1 parent 8f187c7 commit a9d491b

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,6 @@ static bool CheckFunctionConstraintsWithoutInstantiation(
11051105
}
11061106

11071107
Sema::ContextRAII SavedContext(SemaRef, FD);
1108-
std::optional<Sema::CXXThisScopeRAII> ThisScope;
1109-
if (auto *Method = dyn_cast<CXXMethodDecl>(FD))
1110-
ThisScope.emplace(SemaRef, /*Record=*/Method->getParent(),
1111-
/*ThisQuals=*/Method->getMethodQualifiers());
11121108
return SemaRef.CheckConstraintSatisfaction(
11131109
Template, TemplateAC, MLTAL, PointOfInstantiation, Satisfaction);
11141110
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,8 +4749,6 @@ Sema::CheckConceptTemplateId(const CXXScopeSpec &SS,
47494749
EnterExpressionEvaluationContext EECtx{
47504750
*this, ExpressionEvaluationContext::Unevaluated, CSD};
47514751

4752-
ContextRAII CurContext(*this, CSD->getDeclContext(),
4753-
/*NewThisContext=*/false);
47544752
if (!AreArgsDependent &&
47554753
CheckConstraintSatisfaction(
47564754
NamedConcept, AssociatedConstraint(NamedConcept->getConstraintExpr()),

clang/test/SemaTemplate/concepts.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,26 +1228,26 @@ template <KnownKind T> struct KnownType {
12281228

12291229
}
12301230

1231-
namespace GH115838 {
1231+
namespace CWG2369_Regression_2 {
12321232

1233-
template<typename T> concept has_x = requires(T t) {{ t.x };};
1234-
1235-
class Publ { public: int x = 0; };
1236-
class Priv { private: int x = 0; };
1237-
class Prot { protected: int x = 0; };
1238-
class Same { protected: int x = 0; };
1239-
1240-
template<typename T> class D;
1241-
template<typename T> requires ( has_x<T>) class D<T>: public T { public: static constexpr bool has = 1; };
1242-
template<typename T> requires (!has_x<T>) class D<T>: public T { public: static constexpr bool has = 0; };
1233+
template <typename T>
1234+
concept HasFastPropertyForAttribute =
1235+
requires(T element, int name) { element.propertyForAttribute(name); };
1236+
1237+
template <typename OwnerType>
1238+
struct SVGPropertyOwnerRegistry {
1239+
static int fastAnimatedPropertyLookup() {
1240+
static_assert (HasFastPropertyForAttribute<OwnerType>);
1241+
return 1;
1242+
}
1243+
};
12431244

1244-
// "Same" is identical to "Prot" but queried before used.
1245-
static_assert(!has_x<Same>, "Protected should be invisible.");
1246-
static_assert(!D<Same>::has, "Protected should be invisible.");
1245+
class SVGCircleElement {
1246+
friend SVGPropertyOwnerRegistry<SVGCircleElement>;
1247+
void propertyForAttribute(int);
1248+
};
12471249

1248-
static_assert( D<Publ>::has, "Public should be visible.");
1249-
static_assert(!D<Priv>::has, "Private should be invisible.");
1250-
static_assert(!D<Prot>::has, "Protected should be invisible.");
1250+
int i = SVGPropertyOwnerRegistry<SVGCircleElement>::fastAnimatedPropertyLookup();
12511251

12521252
}
12531253

0 commit comments

Comments
 (0)