llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) <details> <summary>Changes</summary> They were sometimes incorrect because the written type doesn't contain an NNS which contains template parameters we're interested in. No release note because the bug broke MS STL and I want to backport it to the last 22.x release Fixes https://github.com/llvm/llvm-project/issues/198663 --- Full diff: https://github.com/llvm/llvm-project/pull/199617.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaConcept.cpp (+10) - (modified) clang/test/SemaTemplate/concepts-using-decl.cpp (+69) ``````````diff diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index ea03c3f408986..66d1f4db29410 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -399,6 +399,16 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> { return true; } + bool TraverseUnresolvedUsingType(UnresolvedUsingType *T, + bool TraverseQualifier) { + // Sometimes the written type doesn't contain a qualifier which contains + // necessary template arguments, whereas the declaration does. + if (NestedNameSpecifier NNS = T->getDecl()->getQualifier(); + TraverseQualifier && NNS) + return inherited::TraverseNestedNameSpecifier(NNS); + return true; + } + bool TraverseInjectedClassNameType(InjectedClassNameType *T, bool TraverseQualifier) { return TraverseTemplateArguments(T->getTemplateArgs(SemaRef.Context)); diff --git a/clang/test/SemaTemplate/concepts-using-decl.cpp b/clang/test/SemaTemplate/concepts-using-decl.cpp index 26bd0b60b691c..dfdab707e4814 100644 --- a/clang/test/SemaTemplate/concepts-using-decl.cpp +++ b/clang/test/SemaTemplate/concepts-using-decl.cpp @@ -197,3 +197,72 @@ struct child : base<int> { }; } + +namespace GH198663 { + +template <class T> +concept HasIsTransparent = requires { typename T::is_transparent; }; + +template <class K, class V, class Compare> +struct FlatMapBase { + using key_compare = Compare; +}; + +template <class K, class V, class Compare> +struct FlatMap : FlatMapBase<K, V, Compare> { + using Base = FlatMapBase<K, V, Compare>; + + using typename Base::key_compare; + + void at(const K&) {} + void at(const K&) const {} + template <class Other> + void at(const Other&) + requires HasIsTransparent<key_compare> + {} + template <class Other> + void at(const Other&) const + requires HasIsTransparent<key_compare> + {} +}; + +template <class T> +struct Transparent { + T t; +}; + +struct TransparentComparator { + using is_transparent = void; + + template <class T> + bool operator()(const T&, const Transparent<T>&) const; + + template <class T> + bool operator()(const Transparent<T>&, const T& t) const; + + template <class T> + bool operator()(const T&, const T&) const; +}; + +struct NonTransparentComparator { + template <class T> + bool operator()(const T&, const Transparent<T>&) const; + + template <class T> + bool operator()(const Transparent<T>&, const T&) const; + + template <class T> + bool operator()(const T&, const T&) const; +}; + +template <class M> +concept CanAt = requires(M m, Transparent<int> k) { m.at(k); }; + +using TransparentMap = FlatMap<int, double, TransparentComparator>; +using NonTransparentMap = FlatMap<int, double, NonTransparentComparator>; + +static_assert(CanAt<TransparentMap>); + +static_assert(!CanAt<NonTransparentMap>); + +} `````````` </details> https://github.com/llvm/llvm-project/pull/199617 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
