Opened 11 years ago

Closed 11 years ago

#5793 closed Bugs (fixed)

[date_time] format_date_parser::parse_date does not compile with "Treat wchar_t as builtin type" set to No

Reported by: Daniel Mitchell <danielmitchell@…> Owned by: Antony Polukhin
Milestone: To Be Determined Component: lexical_cast
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc: antoshkka@…

Description

Testing with Boost 1.47, though it reproduces with trunk as of 19/aug/2011.

Visual Studio 2008 / 2010; the following code does not compile when built with "treat wchar_t as builtin type=no" set in project settings:

#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

void parseDate()
{     
  std::locale locale;
  boost::date_time::format_date_parser<boost::gregorian::date, wchar_t> parser(L"", locale);
  boost::date_time::special_values_parser<boost::gregorian::date, wchar_t> svp; 

  boost::gregorian::date date = parser.parse_date(L"", L"", svp);
}

The compile error is:

c:\source\boost\trunk\boost\lexical_cast.hpp(1406): error C2535: 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator >>(unsigned short &)' : member function already defined or declared
          with
          [
              CharT=char_type,
              Traits=traits,
              RequiresStringbuffer=false
          ]
          c:\source\boost\trunk\boost\lexical_cast.hpp(1392) : see declaration of 'boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator >>'
          with
          [
              CharT=char_type,
              Traits=traits,
              RequiresStringbuffer=false
          ]
          c:\source\boost\trunk\boost\lexical_cast.hpp(1687) : see reference to class template instantiation 'boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>' being compiled
          with
          [
              CharT=char_type,
              Traits=traits,
              RequiresStringbuffer=false
          ]
          c:\source\boost\trunk\boost\lexical_cast.hpp(1653) : while compiling class template member function 'short boost::detail::lexical_cast_do_cast<Target,Source>::lexical_cast_impl(const Source &)'
          with
          [
              Target=short,
              Source=src
          ]
          c:\source\boost\trunk\boost\lexical_cast.hpp(1858) : see reference to class template instantiation 'boost::detail::lexical_cast_do_cast<Target,Source>' being compiled
          with
          [
              Target=short,
              Source=src
          ]
          c:\source\boost\trunk\boost\date_time\format_date_parser.hpp(72) : see reference to function template instantiation 'Target boost::lexical_cast<int_type,std::basic_string<_Elem,_Traits,_Ax>>(const Source &)' being compiled
          with
          [
              Target=short,
              int_type=short,
              _Elem=wchar_t,
              _Traits=std::char_traits<wchar_t>,
              _Ax=std::allocator<wchar_t>,
              Source=std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>
          ]
          c:\source\boost\trunk\boost\date_time\format_date_parser.hpp(365) : see reference to function template instantiation 'int_type boost::date_time::fixed_string_to_int<short,charT>(std::istreambuf_iterator<_Elem,_Traits> &,std::istreambuf_iterator<_Elem,_Traits> &,boost::date_time::parse_match_result<charT> &,unsigned int,const charT &)' being compiled
          with
          [
              int_type=short,
              charT=wchar_t,
              _Elem=wchar_t,
              _Traits=std::char_traits<wchar_t>
          ]
          c:\source\boost\trunk\boost\date_time\format_date_parser.hpp(254) : while compiling class template member function 'boost::gregorian::date boost::date_time::format_date_parser<date_type,charT>::parse_date(std::istreambuf_iterator<_Elem,_Traits> &,std::istreambuf_iterator<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Ax>,const boost::date_time::special_values_parser<date_type,charT> &) const'
          with
          [
              date_type=boost::gregorian::date,
              charT=wchar_t,
              _Elem=wchar_t,
              _Traits=std::char_traits<wchar_t>,
              _Ax=std::allocator<wchar_t>
          ]
          c:\source\dan\boost_wchar_t_test\boost_wchar_t_test\boost_wchar_t_test.cpp(9) : see reference to class template instantiation 'boost::date_time::format_date_parser<date_type,charT>' being compiled
          with
          [
              date_type=boost::gregorian::date,
              charT=wchar_t
          ]

If I set "Treat wchar_t as builtin type" to Yes, then it does compile correctly.

Change History (3)

comment:1 by Ulrich Eckhardt <ulrich.eckhardt@…>, 11 years ago

Component: date_timelexical_cast
Owner: changed from az_sw_dude to Antony Polukhin

Note to the submitter: You are deliberately configuring your compiler to not conform to the C++ standard which requires wchar_t to be a distinct type!

Anyway, I don't think this is a problem in the DateTime library but rather in the lexical_cast implementation. The simple line

std::wstring x = boost::lexical_cast<std::wstring>(42);

triggers the fault for me. Class lexical_stream_limited_src is instantiated for wchar_t alias unsigned short. It defines an operator>> for both unsigned short and its CharT which then cause the conflict. The macro BOOST_NO_INTRINSIC_WCHAR_T could be used to detect this, but I'm not sure how to fix it without breaking other stuff on the way.

comment:2 by Antony Polukhin, 11 years ago

This looks like bug #6186 which is already fixed and merged to release branch (1.49)
Added test case from this ticket in r76809. If regression tests won't fail, I'll close this bug.

comment:3 by Antony Polukhin, 11 years ago

Cc: antoshkka@… added
Resolution: fixed
Status: newclosed

Regression tests passed successfully.

Note: See TracTickets for help on using tickets.