https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106837
--- Comment #2 from Ofek Shilon <ofekshilon at gmail dot com> --- (In reply to Andrew Pinski from comment #1) > > In this case the begin/end iter types *are* comparable > Not exactly as the operator!= requires a lvalue. And end() is not an lvalue. Then enable comparison also via the other iterator type: struct myDat { myDat() {} struct EndIter; struct Iter { Iter &operator++(); int operator*(); bool operator!=(EndIter& other); }; Iter begin() ; struct EndIter { bool operator!=(Iter other); }; EndIter end() ; }; int main() { for (int pos : myDat()) ; } This still fails with the same message