Opened 17 years ago
Closed 16 years ago
#514 closed Bugs (Fixed)
lexical_cast & pure virtual functions & VC 8 STL
Reported by: | sergey_shandar | Owned by: | alnsn |
---|---|---|---|
Milestone: | Component: | None | |
Version: | None | Severity: | |
Keywords: | Cc: |
Description
VC 8.0 can't compile the valid code: ===== ===== #include <boost/lexical_cast.hpp> class A { public: virtual void out(std::ostream &) const = 0; }; class B: public A { public: virtual void out(std::ostream &O) const { O << "B"; } }; std::ostream &operator<<(std::ostream &O, const A &a) { a.out(O); return O; }; int main() { const A &a = B(); boost::lexical_cast<std::string>(a); return 0; } ===== ===== The problem occurs in VC STL: ===== ===== c:\program files\microsoft visual studio 8\vc\include\limits(102) : error C2259: 'A' : cannot instantiate abstract class ===== ===== However, should boost::lexical_cast use std::numeric_cast in this case?
Change History (7)
comment:2 by , 17 years ago
Logged In: NO Perhaps the a being a reference creates the confusion here? The type of a is const & A. And that (as a reference) is copy constructible, even though A is not.
comment:3 by , 16 years ago
Logged In: YES user_id=369903 In my opinion, it is an important use-case. I'd change requirements from - Both Source and Target are CopyConstructible [20.1.3]. to - Target is CopyConstructible [20.1.3]. - Source is CopyConstructible or, if not that, Source is polymorphic and the source value refers to an object with dynamic type SourceDyn which is CopyConstructible and operator<< called for Source is equivalent to operator<< called for SourceDyn.
comment:4 by , 16 years ago
Logged In: YES user_id=32864 I do not believe that there is any longer a reasone that Source needs to be restricted to being CopyConstructible. There were reasons for this in the past, but those have now passed and the requirements can be loosened so that the only requirement on Source is that it is OutputStreamable. This would result in the requirements for the two parameters being as follows: Source: OutputStreamable Target: InputStreamable && CopyConstructible && DefaultConstructible
comment:5 by , 16 years ago
Logged In: YES user_id=369903 Originator: NO Fixed in HEAD. Affected files: M ./boost/lexical_cast.hpp M ./boost/detail/lcast_precision.hpp M ./libs/conversion/lexical_cast.htm M ./libs/conversion/test/Jamfile M ./libs/conversion/test/Jamfile.v2 A ./libs/conversion/test/lexical_cast_abstract_test.cpp Sergey, please check and close.
comment:6 by , 16 years ago
Logged In: YES user_id=369903 Originator: NO See also thread [boost] numeric_limits<Abstract> or how to fix 1358600? http://lists.boost.org/Archives/boost/2007/01/index.php especially John Maddock's proposal http://lists.boost.org/Archives/boost/2007/01/115765.php and my reply.
comment:7 by , 16 years ago
Status: | assigned → closed |
---|
Note:
See TracTickets
for help on using tickets.