https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103583
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- I think the implementation doesn't do anything special to handle this case. It just looks for the members a.begin() and a.end() and then if they aren't found, it goes ahead with rewriting the code to use begin(a) and end(a), and any errors that result from that are shown straight to the user. Another option would be to do lookup for begin(a) and end(a) with errors suppressed, and if they aren't found, issue a custom diagnostic saying something like "no suitable begin/end pair available for range-based 'for' loop". Clang seems to do something similar: f.C:6:18: error: invalid range expression of type 'A'; no viable 'end' function available for (auto it : a) { } ^ ~