[PATCH] Introducing initial UseAuto transform

Dmitri Gribenko gribozavr at gmail.com
Tue Feb 12 10:37:03 PST 2013


On Tue, Feb 12, 2013 at 8:28 PM, Vane, Edwin <edwin.vane at intel.com> wrote:
>   > I'm not sure sugar really matters.
>
>   It does.  `vector<int>::_Iter_type x = ...;` is not valid C++, no matter if it actually compiles on a particular implementation or not.  And transforming non-portable code is asking for trouble.
>
> [REV] Why isn't it valid C++? Is it really our responsibility to test for non-portable code? I understand that by replacing this user-specified type with 'auto' will possibly make code that normally wouldn't compile for some implementations into code that does compile but I think portability testing is beyond scope for the migration tool.  If a user uses an implementation-specific type that makes the code non-portable, should we assume the user did this to make the code non-portable? If the types match while compiling, I would say we can infer the user's intent and use auto and in the process make their code more portable.

It is not valid C++ because vector is not guaranteed to have any extra
members or declarations except for the ones described in the standard.
 And yes, we could guess the intent, but that increases the risk of
the transformation.  To reiterate: transforming non-portable code and
guessing the intent is not 100% solid.

>   > That said, one could foresee an improvement to this transform that tests for unusual sugar and then prompts the user.
>
>   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 /*...*/

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 <gribozavr at gmail.com>*/




More information about the cfe-commits mailing list