This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: template: warning address need more info


Yotam Medini writes:

>  int ip2(const double* p2)
>  {
>     double  m2[2];  m2[0] = 2.;  m2[1] = 3.;
>     double p2m2 = inner_product(p2, p2 + 2, m2, 0);
>  }

Look at the declaration of inner_product:

template <class InputIterator1, class InputIterator2, class T>
T inner_product(InputIterator1 first1, InputIterator1 last1,
                InputIterator2 first2, T init);

Since there doesn't need to be any relation at all between the type of
T with the type of the Iterators, overload resolution succeeded for
you call so that T=int.  Thus, egcs is correct.

> But the warning does not point to the right place, 

It does; it points to the line where the actual warning is.  Anyway,
it would be nice if gcc pointed out why is has expanded such and such
templates, as it does for include files.  This would be a great
addition.

> By the way, shouldn't the (0) be promoted to (0.) automatically?

Only if required.  In this case, since `int' is a valid match, it is
preferred over a promotion to double.

>   * one would expect the warning to be the opposite, that is:
>      assignment to `double' from `int'

Nope.  In fact, the assignment is inside the inner_product template,
that adds to the init value the result of individual elements
products.  At that point, it adds an int to a double, which results a
double, and stores the result back into an int, which causes the
warning to be produced.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]