Move fclose_deleter and null_deleter to their own namespaces to block ADL.

This prevents bringing namespace boost into ADL when the deleters are used
in template parameters, e.g. in std::unique_ptr.
This commit is contained in:
Andrey Semashev
2024-02-02 05:12:41 +03:00
parent 7b1d3718c1
commit 95f0b35c36
6 changed files with 88 additions and 0 deletions

View File

@@ -187,7 +187,12 @@ compile-fail scoped_enum_compile_fail_conv_to_int.cpp
run underlying_type.cpp ;
compile-fail null_deleter_compile_fail_adl.cpp
: $(warnings-as-errors-off) ;
run fclose_deleter_test.cpp : : : <target-os>windows:<define>_CRT_SECURE_NO_WARNINGS <target-os>windows:<define>_CRT_SECURE_NO_DEPRECATE ;
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 ;

View File

@@ -0,0 +1,30 @@
/*
* 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 fclose_deleter_compile_fail_adl.cpp
* \author Andrey Semashev
* \date 02.02.2024
*
* This file tests that \c boost::fclose_deleter doesn't bring namespace
* boost into ADL.
*/
#include <boost/core/fclose_deleter.hpp>
namespace boost {
void check_adl(fclose_deleter const&)
{
}
} // namespace boost
int main()
{
// Must not find boost::check_adl
check_adl(boost::fclose_deleter());
}

View File

@@ -0,0 +1,30 @@
/*
* 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 fclose_deleter_compile_fail_adl.cpp
* \author Andrey Semashev
* \date 02.02.2024
*
* This file tests that \c boost::null_deleter doesn't bring namespace
* boost into ADL.
*/
#include <boost/core/null_deleter.hpp>
namespace boost {
void check_adl(null_deleter const&)
{
}
} // namespace boost
int main()
{
// Must not find boost::check_adl
check_adl(boost::null_deleter());
}