On Tue, Feb 12, 2013 at 9:48 PM, Vane, Edwin <[email protected]> wrote:
>> It can be done easier, I think. We know that all functions that return
>> iterators have a return value type with correct sugar. That is,
>> `vector<T>::begin()` return value is always `vector<T>::iterator`.
>>
>> [REV] This isn't always true. When dealing with for-loops I found from
>> dumping the AST that you don't get vector<T>::iterator but whatever
>> vector<T>::iterator typedefs to which is quite long and complex with
>> libstdc++. It was this realization that prompted the comparison of canonical
>> types.
>
> I guess there is something not entirely correct in that test, because this is
> what I see in my copy of libstdc++ 4.7:
>
> iterator
> begin() _GLIBCXX_NOEXCEPT /*...*/
>
> [REV] I put this:
>
> llvm::errs() << D->getType().getAsString() << " = " <<
> E->getType().getAsString() << "\n";
>
> right before the cananonical type equality test. Here's the output when
> running the iterator.cpp test:
>
> class MyIterator = class MyIterator
> class DummyIterator = class DummyIterator
> std::vector<int>::iterator = iterator
> int_iterator = std::vector<int>::iterator
> std::vector<int>::iterator = iterator
> std::vector<int>::reverse_iterator = reverse_iterator
> std::vector<int>::iterator = iterator
> std::vector<int>::iterator = class __gnu_cxx::__normal_iterator<int *, class
> std::vector<int, class std::allocator<int> > >
> int_iterator = iterator
> int_iterator = iterator
>
> Notice how the RHS type, even though not user-provided, varies quite a lot.
All of these look good (they should be processed by that algorithm
correctly), except for the 'class __gnu_cxx::...' -- it comes from a
'__begin' variable in the range-based for, which comes from 'auto'
deduction, which is implemented as argument type deduction. Might be
fixable, though non-trivial.
> This is with libstdc++4.7. I'm not entirely sure this matters. From what
> you're suggesting about unsugaring user types it sounds like we do the
> canonical type test and then do an extra bit of work to make sure the
> user-provided type is no less sugared than the types allowed by the spec?
Yes.
> How do you propose we deal with custom iterators? The canonical type may then
> be the LHS type.
The user is free to do whatever crazy stuff they like with their
iterators, I don't think we should check anything there.
Given the apparent complexity of implementing the check for all cases,
I think we can leave it for later.
Dmitri
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <[email protected]>*/
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits