[LLVMdev] subtle problem with inst_iterator
Vladimir Prus
ghost at cs.msu.su
Fri Apr 23 07:13:01 PDT 2004
Hello, I think there's a rather subtle problem with the inst_iterator. It
declares its iterator category as std::bidirectional_iterator_tag but C++
standard requirements for forward iterator (which are included in
requirements for bidirection iterator), say that the type of expression
*r;
should be T&, where 'r' is the iterator and T is its value type. The
inst_iterator, though, returns pointer to Instruction, not a reference to a
pointer to instruction.
The above might sound like I've gone crazy reading C++ standard, but my real
reason is that with the current code the following:
for_each(inst_begin(f), inst_end(f), boost::bind(
apply_phi_semantics, result, _1, instruction2vertex));
does not compile, where 'apply_phi_semantics' is my function and boost::bind
is a tool for binding function arguments described in
http://www.boost.org/libs/bind/bind.html
The reason it does not compile is somewhat contrived. for_each passes the
result of *it to functional object returned by boost::bind. The operator() of
that object has the following signature:
template<class Arg1>
.... operator()(Arg& a1)
and since result of *it is considered to be rvalue it can't be accepted by
this operator. The complete discussion is in
http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm
I'd suggest to apply the following patch which makes operator* return
reference to pointer. It makes my code compile and the rest of LLVM compiles
too. Comments?
- Volodya
-------------- next part --------------
A non-text attachment was scrubbed...
Name: iterator.diff
Type: text/x-diff
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20040423/a6c17e60/attachment.diff>
More information about the llvm-dev
mailing list