https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84009
Bug ID: 84009 Summary: No diagnostic issued if the decl-specifier in the decl-specifier-seq of a for-range-declaration is register, static,or thread_local Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: smw at gcc dot gnu.org Target Milestone: --- The C++ standard requires the decl-specifier in the decl-specifier-seq of a for-range-declaration shall be either a type-specifier or constexpr ([stmt.ranged]/2). GCC does so for most decl-specifiers (eg. "friend", "mutable", "extern", etc) but not for "register," "static," or "thread_local." This is in C++14 mode (so, um, "register" isn't even a valid decl-specifier any more). clang, MSVC, ICC all give appropriate diagnostics in this case. GCC (all versions tested, up to 8.0.1 20180117) remains mute. Here's a sample bit of code that should not compile silently. void f() { int a[] = { 1, 2, 3 }; for (register int& i : a) { // ... } }