[libcxx-commits] [PATCH] D74287: [libcxx] Fix unintended ADL inside ref(reference_wrapper<T>) and cref(reference_wrapper<T>)
Logan Smith via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Feb 8 12:42:48 PST 2020
logan-5 created this revision.
logan-5 added reviewers: EricWF, mclow.lists.
logan-5 added a project: libc++.
Herald added subscribers: libcxx-commits, ldionne, christof.
This patch qualifies calls to `ref` and `cref` inside `ref(reference_wrapper<T>)` and `cref(reference_wrapper<T>)`, respectively. These previously unqualified calls could break in the presence of user functions called ref/cref inside associated namespaces: https://gcc.godbolt.org/z/8VfprT
Fixes https://bugs.llvm.org/show_bug.cgi?id=44398.
Thanks to @Quuxplusone for creating that Godbolt test case and submitting the bug.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D74287
Files:
libcxx/include/__functional_base
libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
Index: libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
===================================================================
--- libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
+++ libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/ref_2.pass.cpp
@@ -24,6 +24,11 @@
template <typename T>
bool call_pred ( T pred ) { return pred(5); }
+namespace adl {
+ struct A {};
+ void ref(A) {}
+}
+
int main(int, char**)
{
{
@@ -32,6 +37,13 @@
std::reference_wrapper<int> r2 = std::ref(r1);
assert(&r2.get() == &i);
}
+ {
+ adl::A a;
+ std::reference_wrapper<adl::A> a1 = std::ref(a);
+ std::reference_wrapper<adl::A> a2 = std::ref(a1);
+ assert(&a2.get() == &a);
+ }
+
{
unary_counting_predicate<bool(*)(int), int> cp(is5);
assert(!cp(6));
Index: libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
===================================================================
--- libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
+++ libcxx/test/std/utilities/function.objects/refwrap/refwrap.helpers/cref_2.pass.cpp
@@ -17,6 +17,11 @@
#include "test_macros.h"
+namespace adl {
+ struct A {};
+ void cref(A) {}
+}
+
int main(int, char**)
{
const int i = 0;
@@ -24,5 +29,12 @@
std::reference_wrapper<const int> r2 = std::cref(r1);
assert(&r2.get() == &i);
+ {
+ adl::A a;
+ std::reference_wrapper<const adl::A> a1 = std::cref(a);
+ std::reference_wrapper<const adl::A> a2 = std::cref(a1);
+ assert(&a2.get() == &a);
+ }
+
return 0;
}
Index: libcxx/include/__functional_base
===================================================================
--- libcxx/include/__functional_base
+++ libcxx/include/__functional_base
@@ -522,7 +522,7 @@
reference_wrapper<_Tp>
ref(reference_wrapper<_Tp> __t) _NOEXCEPT
{
- return ref(__t.get());
+ return _VSTD::ref(__t.get());
}
template <class _Tp>
@@ -538,7 +538,7 @@
reference_wrapper<const _Tp>
cref(reference_wrapper<_Tp> __t) _NOEXCEPT
{
- return cref(__t.get());
+ return _VSTD::cref(__t.get());
}
#ifndef _LIBCPP_CXX03_LANG
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74287.243399.patch
Type: text/x-patch
Size: 2226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200208/cb9b2891/attachment.bin>
More information about the libcxx-commits
mailing list