Added definitions for path static constants.

This fixes compilation if user's code attempts to ODR-use the constants.

Fixes https://svn.boost.org/trac10/ticket/12759.
Closes https://github.com/boostorg/filesystem/pull/40.
This commit is contained in:
Andrey Semashev 2018-11-24 20:26:45 +03:00
parent 613df5a93d
commit 8de281773f
3 changed files with 22 additions and 6 deletions

View File

@ -61,14 +61,14 @@ namespace filesystem
# ifdef BOOST_WINDOWS_API
typedef wchar_t value_type;
BOOST_STATIC_CONSTEXPR value_type separator = L'/';
BOOST_STATIC_CONSTEXPR value_type preferred_separator = L'\\';
BOOST_STATIC_CONSTEXPR value_type dot = L'.';
static BOOST_CONSTEXPR_OR_CONST value_type separator = L'/';
static BOOST_CONSTEXPR_OR_CONST value_type preferred_separator = L'\\';
static BOOST_CONSTEXPR_OR_CONST value_type dot = L'.';
# else
typedef char value_type;
BOOST_STATIC_CONSTEXPR value_type separator = '/';
BOOST_STATIC_CONSTEXPR value_type preferred_separator = '/';
BOOST_STATIC_CONSTEXPR value_type dot = '.';
static BOOST_CONSTEXPR_OR_CONST value_type separator = '/';
static BOOST_CONSTEXPR_OR_CONST value_type preferred_separator = '/';
static BOOST_CONSTEXPR_OR_CONST value_type dot = '.';
# endif
typedef std::basic_string<value_type> string_type;
typedef std::codecvt<wchar_t, char,

View File

@ -125,6 +125,10 @@ namespace boost
{
namespace filesystem
{
BOOST_CONSTEXPR_OR_CONST path::value_type path::separator;
BOOST_CONSTEXPR_OR_CONST path::value_type path::preferred_separator;
BOOST_CONSTEXPR_OR_CONST path::value_type path::dot;
path& path::operator/=(const path& p)
{
if (p.empty())

View File

@ -1934,6 +1934,12 @@ namespace
}
}
inline void odr_use(const path::value_type& c)
{
static const path::value_type dummy = '\0';
BOOST_TEST(&c != &dummy);
}
} // unnamed namespace
static boost::filesystem::path ticket_6737 = "FilePath"; // #6737 reported this crashed
@ -2029,5 +2035,11 @@ int cpp_main(int, char*[])
std::cout << round_trip.string() << "..." << round_trip << " complete\n";
# endif
// Check that path constants have definitions
// https://svn.boost.org/trac10/ticket/12759
odr_use(path::separator);
odr_use(path::preferred_separator);
odr_use(path::dot);
return ::boost::report_errors();
}