Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2407 closed Bugs (fixed)

[Proto] Error while using operator<< and iostream

Reported by: Joel Falcou <joel.falcou@…> Owned by: Eric Niebler
Milestone: Boost 1.37.0 Component: proto
Version: Boost Development Trunk Severity: Problem
Keywords: Proto Cc:

Description

Bug found in the "[Boost-users] [Proto] Strange behavior with semantic action and custom tag function" threads.

Quoting Eric : "The operator<< in the output expression can potentially match either the ostream inserter we've defined above or Proto's operator<<. Proto's operator overload *should* be disabled with SFINAE because the resulting expression type doesn't match the domain's grammar. But the failure happens before we get that far. Before checking the return type against the grammar, Proto first calculates the return type, which first involves Protofying std::cout, resulting in e<proto::terminal<std::ostream &>::type>. This is where the failure occurs because this simple terminal expression *also* doesn't match the grammar. That triggers the static assertion failure in e<>."

Attachments (0)

Change History (4)

comment:1 Changed 9 years ago by Eric Niebler

Owner: set to Eric Niebler
Status: newassigned
#include <iostream>
#include <boost/proto/proto.hpp>

namespace mpl = boost::mpl;
namespace proto = boost::proto;
using proto::_;

template<class E>
struct e;

struct g
  : proto::or_<
        proto::terminal<int>
      , proto::plus<g,g>
    >
{};

struct d
  : proto::domain<proto::generator<e>, g>
{};

template<class E>
struct e
  : proto::extends<E, e<E>, d>
{
    BOOST_MPL_ASSERT((proto::matches<E, g>));

    e(E const &x = E())
      : proto::extends<E, e<E>, d>(x)
    {}
};

e<proto::terminal<int>::type> i;

template<class E>
std::ostream &operator<<(std::ostream &sout, e<E> const &x)
{
    return sout;
}

int main()
{
    std::cout << (i+i);
}

comment:2 Changed 9 years ago by Eric Niebler

Component: Noneproto

comment:3 Changed 9 years ago by Eric Niebler

Resolution: fixed
Status: assignedclosed

(In [49812]) fix #2407

comment:4 Changed 9 years ago by Eric Niebler

(In [49820]) fix bug 2407

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Eric Niebler.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.