This revision was automatically updated to reflect the committed changes. Closed by commit rG122b938944ce: [Clang][Sema] Substitute constraints only for declarations with different… (authored by alexander-shaposhnikov).
Changed prior to commit: https://reviews.llvm.org/D150730?vs=522856&id=523179#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150730/new/ https://reviews.llvm.org/D150730 Files: clang/lib/Sema/SemaConcept.cpp clang/test/SemaTemplate/concepts-no-early-substitution.cpp Index: clang/test/SemaTemplate/concepts-no-early-substitution.cpp =================================================================== --- /dev/null +++ clang/test/SemaTemplate/concepts-no-early-substitution.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -std=c++20 -x c++ %s -verify -fsyntax-only +// expected-no-diagnostics + +template <typename T0> +concept HasMemberBegin = requires(T0 t) { t.begin(); }; + +struct GetBegin { + template <HasMemberBegin T1> + void operator()(T1); +}; + +GetBegin begin; + +template <typename T2> +concept Concept = requires(T2 t) { begin(t); }; + +struct Subrange; + +template <typename T3> +struct View { + Subrange &getSubrange(); + + operator bool() + requires true; + + operator bool() + requires requires { begin(getSubrange()); }; + + void begin(); +}; + +struct Subrange : View<void> {}; +static_assert(Concept<Subrange>); Index: clang/lib/Sema/SemaConcept.cpp =================================================================== --- clang/lib/Sema/SemaConcept.cpp +++ clang/lib/Sema/SemaConcept.cpp @@ -780,7 +780,9 @@ const Expr *NewConstr) { if (OldConstr == NewConstr) return true; - if (Old && New && Old != New) { + // C++ [temp.constr.decl]p4 + if (Old && New && Old != New && + Old->getLexicalDeclContext() != New->getLexicalDeclContext()) { if (const Expr *SubstConstr = SubstituteConstraintExpression(*this, Old, OldConstr)) OldConstr = SubstConstr;
Index: clang/test/SemaTemplate/concepts-no-early-substitution.cpp =================================================================== --- /dev/null +++ clang/test/SemaTemplate/concepts-no-early-substitution.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -std=c++20 -x c++ %s -verify -fsyntax-only +// expected-no-diagnostics + +template <typename T0> +concept HasMemberBegin = requires(T0 t) { t.begin(); }; + +struct GetBegin { + template <HasMemberBegin T1> + void operator()(T1); +}; + +GetBegin begin; + +template <typename T2> +concept Concept = requires(T2 t) { begin(t); }; + +struct Subrange; + +template <typename T3> +struct View { + Subrange &getSubrange(); + + operator bool() + requires true; + + operator bool() + requires requires { begin(getSubrange()); }; + + void begin(); +}; + +struct Subrange : View<void> {}; +static_assert(Concept<Subrange>); Index: clang/lib/Sema/SemaConcept.cpp =================================================================== --- clang/lib/Sema/SemaConcept.cpp +++ clang/lib/Sema/SemaConcept.cpp @@ -780,7 +780,9 @@ const Expr *NewConstr) { if (OldConstr == NewConstr) return true; - if (Old && New && Old != New) { + // C++ [temp.constr.decl]p4 + if (Old && New && Old != New && + Old->getLexicalDeclContext() != New->getLexicalDeclContext()) { if (const Expr *SubstConstr = SubstituteConstraintExpression(*this, Old, OldConstr)) OldConstr = SubstConstr;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits