dr...@furrfu.invalid (Drew Lawson) wrote in
news:m23ihk$2s1d$
1...@raid.furrfu.com:
> I realize this is a toolset problem, not a language problem. I'd
> appreciate hearing about any C++ compilers that don't spew line
> noise for cases like this.
I did a little experimentation with online compilers. The program is
here:
#include <vector>
#include <string>
int main() {
std::vector<std::string> abc;
abc.push_back("a");
std::vector<std::string>::const_iterator it = abc.begin();
*it = "b";
}
The error messages I got are below. It appears Intel's icc is actually
producing the most helpful message.
---------------------
icc 13.0:
/tmp/gcc-explorer-compiler114920-17793-151o21n/example.cpp(7): error: no
operator "=" matches these operands
operand types are: const std::string = const char [2]
---------------------
gcc 4.9.0:
/tmp/gcc-explorer-compiler114920-29276-1xukbcf/example.cpp: In function
‘int main()’:
7 : error: passing ‘const std::basic_string’ as ‘this’ argument of
‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT,
_Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char; _Traits =
std::char_traits; _Alloc = std::allocator]’ discards qualifiers [-
fpermissive]
---------------------
clang 3.4.1
7 : error: no viable overloaded '='
*it = "b";
~~~ ^ ~~~
/usr/lib/gcc/x86_64-linux-
gnu/4.8/../../../../include/c++/4.8/bits/basic_string.h:546:7: note:
candidate function not viable: 'this' argument has type 'const
std::basic_string<char>', but method is not marked const
operator=(const basic_string& __str)
^
/usr/lib/gcc/x86_64-linux-
gnu/4.8/../../../../include/c++/4.8/bits/basic_string.h:554:7: note:
candidate function not viable: 'this' argument has type 'const
std::basic_string<char>', but method is not marked const
operator=(const _CharT* __s)
^
/usr/lib/gcc/x86_64-linux-
gnu/4.8/../../../../include/c++/4.8/bits/basic_string.h:565:7: note:
candidate function not viable: 'this' argument has type 'const
std::basic_string<char>', but method is not marked const
operator=(_CharT __c)
^
-----------------------------
MSVC 2012:
test.cpp(7): error C2678: binary '=' : no operator found which takes a
left-hand operand of type 'const std::basic_string<_Elem,_Traits,
_Alloc>' (or there is no acceptable conversion)
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
\xstring(912): could be 'std::basic_string<_Elem,_Traits,_Alloc>
&std::basic_string<_Elem,_Traits,_Alloc>::operator =(std::basic_string
<_Elem,_Traits,_Alloc> &&) throw()'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
\xstring(969): or 'std::basic_string<_Elem,_Traits,_Alloc>
&std::basic_string<_Elem,_Traits,_Alloc>::operator =(const
std::basic_string<_Elem,_Traits,_Alloc> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
\xstring(987): or 'std::basic_string<_Elem,_Traits,_Alloc>
&std::basic_string<_Elem,_Traits,_Alloc>::operator =(const _Elem *)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
\xstring(992): or 'std::basic_string<_Elem,_Traits,_Alloc>
&std::basic_string<_Elem,_Traits,_Alloc>::operator =(_Elem)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
while trying to match the argument list '(const
std::basic_string<_Elem,_Traits,_Alloc>, const char [2])'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
-------------------------------