mirror of
https://github.com/boostorg/filesystem.git
synced 2026-01-19 04:12:09 +00:00
Disabled construction and assignment of path from nullptr.
It is always an error and UB. Explicitly deleting the functions produces better compiler errors. Closes https://github.com/boostorg/filesystem/issues/278.
This commit is contained in:
@@ -489,6 +489,9 @@ struct is_convertible_to_path_source
|
||||
#endif
|
||||
static yes_type _check_convertible_to_path_source(boost::basic_string_view< char, std::char_traits< char > > const&);
|
||||
static yes_type _check_convertible_to_path_source(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR)
|
||||
static no_type _check_convertible_to_path_source(std::nullptr_t);
|
||||
#endif
|
||||
static no_type _check_convertible_to_path_source(...);
|
||||
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value =
|
||||
@@ -508,6 +511,9 @@ struct is_convertible_to_std_string_view
|
||||
{
|
||||
static yes_type _check_convertible_to_std_string_view(std::string_view const&);
|
||||
static yes_type _check_convertible_to_std_string_view(std::wstring_view const&);
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR)
|
||||
static no_type _check_convertible_to_std_string_view(std::nullptr_t);
|
||||
#endif
|
||||
static no_type _check_convertible_to_std_string_view(...);
|
||||
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value =
|
||||
@@ -526,6 +532,9 @@ struct is_convertible_to_path_source_non_std_string_view
|
||||
static yes_type _check_convertible_to_path_source(boost::container::basic_string< wchar_t, std::char_traits< wchar_t >, void > const&);
|
||||
static yes_type _check_convertible_to_path_source(boost::basic_string_view< char, std::char_traits< char > > const&);
|
||||
static yes_type _check_convertible_to_path_source(boost::basic_string_view< wchar_t, std::char_traits< wchar_t > > const&);
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR)
|
||||
static no_type _check_convertible_to_path_source(std::nullptr_t);
|
||||
#endif
|
||||
static no_type _check_convertible_to_path_source(...);
|
||||
|
||||
static BOOST_CONSTEXPR_OR_CONST bool value =
|
||||
|
||||
@@ -446,6 +446,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_NULLPTR)
|
||||
BOOST_DELETED_FUNCTION(path(std::nullptr_t))
|
||||
BOOST_DELETED_FUNCTION(path& operator= (std::nullptr_t))
|
||||
#endif
|
||||
|
||||
public:
|
||||
// ----- assignments -----
|
||||
|
||||
// We need to explicitly define copy assignment as otherwise it will be implicitly defined as deleted because there is move assignment
|
||||
|
||||
@@ -84,6 +84,7 @@ run operations_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 <t
|
||||
run operations_test.cpp : : : <link>static <define>BOOST_FILESYSTEM_VERSION=4 : operations_test_static ;
|
||||
run operations_unit_test.cpp : $(HERE) : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 <test-info>always_show_run_output ;
|
||||
run copy_test.cpp : : : <define>BOOST_FILESYSTEM_VERSION=4 ;
|
||||
compile-fail cf_path_nullptr_test.cpp ;
|
||||
run path_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=4 ;
|
||||
run path_test.cpp : : : <link>static <define>BOOST_FILESYSTEM_VERSION=4 : path_test_static ;
|
||||
run path_test.cpp : : : <link>shared <define>BOOST_FILESYSTEM_VERSION=3 : path_test_v3 ;
|
||||
|
||||
19
test/cf_path_nullptr_test.cpp
Normal file
19
test/cf_path_nullptr_test.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2023 Andrey Semashev.
|
||||
//
|
||||
// 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
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_NULLPTR)
|
||||
#error "This test requires support for C++11 nullptr"
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::filesystem::path p(nullptr);
|
||||
p = nullptr;
|
||||
}
|
||||
Reference in New Issue
Block a user