Skip to content

Commit 87988fc

Browse files
committed
[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 80a6bc7 commit 87988fc

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@ Bug Fixes to C++ Support
953953
- Fixed an access checking bug when initializing non-aggregates in default arguments (#GH62444), (#GH83608)
954954
- Fixed a pack substitution bug in deducing class template partial specializations. (#GH53609)
955955
- Fixed a crash when constant evaluating some explicit object member assignment operators. (#GH142835)
956-
- Fixed an access checking bug when substituting into concepts (#GH115838)
957956
- Fix a bug where private access specifier of overloaded function not respected. (#GH107629)
958957
- Correctly handles calling an explicit object member function template overload set
959958
through its address (``(&Foo::bar<baz>)()``).

clang/lib/Sema/SemaConcept.cpp

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

10991099
Sema::ContextRAII SavedContext(SemaRef, FD);
1100-
std::optional<Sema::CXXThisScopeRAII> ThisScope;
1101-
if (auto *Method = dyn_cast<CXXMethodDecl>(FD))
1102-
ThisScope.emplace(SemaRef, /*Record=*/Method->getParent(),
1103-
/*ThisQuals=*/Method->getMethodQualifiers());
11041100
return SemaRef.CheckConstraintSatisfaction(
11051101
Template, TemplateAC, MLTAL, PointOfInstantiation, Satisfaction);
11061102
}

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,25 +1228,25 @@ 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
}

0 commit comments

Comments
 (0)