Skip to content

Commit

Permalink
Added definitions for path static constants.
Browse files Browse the repository at this point in the history
This fixes compilation if user's code attempts to ODR-use the constants.

Fixes https://svn.boost.org/trac10/ticket/12759.
Closes #40.
  • Loading branch information
Lastique committed Nov 24, 2018
1 parent 613df5a commit 8de2817
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/boost/filesystem/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 12 additions & 0 deletions test/path_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

0 comments on commit 8de2817

Please sign in to comment.