No compiler warnings were generated for this, but should one have been?
There is nothing declared in the Standard that should make GCC generate a warning for that case.
You could extend begin()
, by marking it as WARN_UNUSED
, where first you would have define:
#define WARN_UNUSED __attribute__((warn_unused_result))
as described here, but this of course it's not exactly you are looking for, but it's something. I can't find any option of GCC to generate a warning in your case.
It is a known GCC bug though, but hasn't implemented the functionality you are looking for, at least until 2017-07-21.
However, clang 6.0.0 issues a warning for this, (even if Wall
and Wextra
flags are not used):
prog.cc:11:18: warning: equality comparison result unused [-Wunused-comparison]
this->it == this->myVector.begin();
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
prog.cc:11:18: note: use '=' to turn this equality comparison into an assignment
this->it == this->myVector.begin();
^~
=
1 warning generated.
Moreover, zapcc 1.0.1 issues a warning as well (again even without the warning flags):
/home/jail/prog.cc:11:18: warning: equality comparison result unused [-Wunused-comparison]
this->it == this->myVector.begin();
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/home/jail/prog.cc:11:18: note: use '=' to turn this equality comparison into an assignment
this->it == this->myVector.begin();
^~
=
1 warning generated.
View it yourself in Wandbox, if you like.