Repository navigation
Description
Issue Summary
The front end incorrectly accepts range-based for statements whose begin and end functions are found only by ordinary unqualified lookup or only in a non-associated namespace std. CWG 1442 requires these names to be found by argument-dependent lookup alone, without treating std as an associated namespace unless it is associated with the range type.
Reproducing Source Code
namespace N {
struct A {};
struct B {};
}
// Visible to ordinary unqualified lookup, but not to ADL.
int *begin(N::A &);
int *end(N::A &);
namespace std {
// std is not associated with N::B.
int *begin(N::B &);
int *end(N::B &);
}
void f(N::A &a, N::B &b) {
for (int x : a) {}
for (int x : b) {}
}Command-line Options
--c++11
Type of Issue
[Front End] This code SHOULD NOT compile with these options.
Additional Details
CWG 1442 clarifies that begin(__range) and end(__range) are looked up in the associated namespaces. Ordinary unqualified lookup is not performed, and namespace std is not automatically an associated namespace.
Both loops above should therefore be rejected because no suitable begin or end function can be found by argument-dependent lookup. The first loop incorrectly uses the global functions, while the second incorrectly uses the functions declared in std.
Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
- I have checked open issues and existing discussions before filing this report.
- The reproducing source code that I have provided does not depend on headers that I have not included with my submission.
- I have reduced the reproducing source code to the best of my ability.
- I have selected at least one standard configuration or uploaded a non-standard configuration dump.
- I understand code shared via this form is NOT confidential.
- I have permission to share the reproducing source code and grant permission for the project to use the source code (or derivatives of the source code) to create tests.
- I agree that any tests created using the reproducing source code (or deriatives of it) will be licensed under project license unless I included a
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.
Activity
Argument-dependent lookup in range-based for and structured bindings …
Argument-dependent lookup in range-based for and structured bindings …