Ticket #2015: format.patch

File format.patch, 3.2 KB (added by Steven Watanabe, 13 years ago)

Fix for the problem

  • boost/format/format_class.hpp

     
    6868            { return io::detail::feed<CharT, Tr, Alloc, T&>(*this,x); }
    6969#endif
    7070
     71#ifdef __GNUC__
     72        // GCC can't handle anonymous enums without some help
     73        // ** arguments passing ** //
     74        basic_format&   operator%(const int& x)
     75            { return io::detail::feed<CharT, Tr, Alloc, const int&>(*this,x); }
     76
     77#ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
     78        basic_format&   operator%(int& x)
     79            { return io::detail::feed<CharT, Tr, Alloc, int&>(*this,x); }
     80#endif
     81#endif
     82
    7183        // ** object modifying **//
    7284        template<class T>
    7385        basic_format&  bind_arg(int argN, const T& val)
  • libs/format/test/format_test_enum.cpp

     
     1// ------------------------------------------------------------------------------
     2//  format_test_enum.cpp :  test format use with enums
     3// ------------------------------------------------------------------------------
     4
     5//  Copyright Steven Watanabe 2009.
     6//
     7//  Distributed under the Boost Software License, Version 1.0. (See
     8//  accompanying file LICENSE_1_0.txt or copy at
     9//  http://www.boost.org/LICENSE_1_0.txt)
     10
     11//  See http://www.boost.org/libs/format for library home page
     12
     13// ------------------------------------------------------------------------------
     14
     15#include "boost/format.hpp"
     16
     17#define BOOST_INCLUDE_MAIN
     18#include <boost/test/test_tools.hpp>
     19
     20enum enum_plain { PLAIN };
     21enum { ANONYMOUS };
     22enum enum_overloaded { OVERLOADED };
     23typedef enum { OVERLOADED_TYPEDEF } enum_overloaded_typedef;
     24
     25std::ostream& operator<<(std::ostream& os, enum_overloaded) {
     26    os << "overloaded";
     27    return(os);
     28}
     29
     30std::ostream& operator<<(std::ostream& os, enum_overloaded_typedef) {
     31    os << "overloaded";
     32    return(os);
     33}
     34
     35int test_main(int, char*[]) {
     36    // in this case, we should implicitly convert to int
     37    BOOST_CHECK_EQUAL((boost::format("%d") % PLAIN).str(), "0");
     38    BOOST_CHECK_EQUAL((boost::format("%d") % ANONYMOUS).str(), "0");
     39
     40    // but here we need to use the overloaded operator
     41    BOOST_CHECK_EQUAL((boost::format("%s") % OVERLOADED).str(), "overloaded");
     42    BOOST_CHECK_EQUAL((boost::format("%s") % OVERLOADED_TYPEDEF).str(), "overloaded");
     43
     44    return 0;
     45}
  • libs/format/test/Jamfile.v2

    Property changes on: libs\format\test\format_test_enum.cpp
    ___________________________________________________________________
    Name: svn:mime-type
       + text/plain
    Name: svn:keywords
       + Id
    Name: svn:eol-style
       + native
    
     
    1818        [ run format_test2.cpp ]
    1919        [ run format_test3.cpp ]
    2020        [ run format_test_wstring.cpp ]
     21        [ run format_test_enum.cpp ]
    2122  ;
    2223}
    2324