lundi 24 juillet 2017

Confusing error message by clang

I was learning C++11 and wrote the following using clang shipped with Ubuntu 16.04

#include <iostream>

int main()
{
    for(const int &i : {1,2,3,4,5,6})
    {
        std::cout <<  i = 2 * i << std::endl;
    }
}

and clang++ produces

range_for.cc:9:36: error: reference to overloaded function could not be resolved; did you mean to call it?
    std::cout <<  i = 2 * i << std::endl;
                               ^~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/ostream:590:5: note: possible target for call
endl(basic_ostream<_CharT, _Traits>& __os)
^
1 error generated.

I thought the error should be trying to modify to const int & but instead got a somewhat confusing message. What is the logic?

Aucun commentaire:

Enregistrer un commentaire