Move functor to its own namespace to block bringing boost::core to ADL.

This commit is contained in:
Andrey Semashev
2024-02-02 05:23:00 +03:00
parent 95f0b35c36
commit 0a35bb6a20
3 changed files with 42 additions and 0 deletions

View File

@@ -18,6 +18,9 @@
namespace boost::core {
// Block unintended ADL
namespace functor_ns {
//! A function object that invokes a function specified as its template parameter
template< auto Function >
struct functor
@@ -29,6 +32,10 @@ struct functor
}
};
} // namespace functor_ns
using functor_ns::functor;
} // namespace boost::core
#endif // BOOST_CORE_FUNCTOR_HPP

View File

@@ -195,6 +195,9 @@ compile-fail fclose_deleter_compile_fail_adl.cpp
: <target-os>windows:<define>_CRT_SECURE_NO_WARNINGS <target-os>windows:<define>_CRT_SECURE_NO_DEPRECATE $(warnings-as-errors-off) ;
run functor_test.cpp ;
compile-fail functor_compile_fail_adl.cpp
: $(warnings-as-errors-off) ;
run pointer_traits_pointer_test.cpp ;
run pointer_traits_element_type_test.cpp ;

View File

@@ -0,0 +1,32 @@
/*
* Copyright Andrey Semashev 2024.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file functor_compile_fail_adl.cpp
* \author Andrey Semashev
* \date 02.02.2024
*
* This file tests that \c boost::core::functor doesn't bring namespace
* boost::core into ADL.
*/
#include <boost/core/functor.hpp>
void func() {}
namespace boost::core {
void check_adl(functor< ::func > const&)
{
}
} // namespace boost::core
int main()
{
// Must not find boost::check_adl
check_adl(boost::core::functor< ::func >());
}