Home Dashboard Directory Help

std::begin and std::end ADL lookup failure by njoubert1


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 698286
Opened: 11/1/2011 12:58:00 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
User(s) can reproduce this bug


To whom it may concern

The following code fails to compile, it requires the two using's to be uncommented to compile. It should compile. the array is found in the std namespace, so via the normal ADL lookup, it should find the begin and end in the std namespace.

I know that the std::array is currently defined in the std::tr1 namespace, and is introduced into the std namespace via a using, should this not be the other way round?

If the two using's (commented out) are required, it makes generic code as recommended here; http://herbsutter.com/elements-of-modern-c-style/, (section Nonmember begin and end) more difficult to write and slightly counter intuitive (especially when writing generic code).

#include <iostream>
#include <algorithm>
#include <array>
#include <iterator>

void main()
    std::array<int, 7> abc = { 1, 2, 3, 4, 5, 6, 7 };
    //using std::begin;
    //using std::end;
    std::copy(begin(abc), end(abc), std::ostream_iterator<int>(std::cout, " "));
Sign in to post a comment.
Posted by Microsoft on 11/2/2011 at 4:27 PM

Thanks for reporting this bug. We've already fixed it, and you can observe the fix in the VC11 Developer Preview.

We originally implemented TR1 in VC9 SP1. In VC10, we implemented most of the C++0x Standard Library (according to the Working Papers available at the time, modulo compiler features, and excluding threads/atomics - there was just no way to cram any more Standard Library work into VC10). For originally-from-TR1 components like array and shared_ptr, we left them in std::tr1 to save time, and dragged them into std with using-declarations. This was unobservable to most users, except that the True Names are displayed in the debugger, and ADL and specializations are also sensitive to the difference.

In VC11, we've "flipped" things so that originally-from-TR1 components are defined in std (conforming to C++11) and then dragged into std::tr1 with using-declarations for backwards compatibility. This fixes your ADL example.

By the way, main() returns int in Standard C++, and you should compile native code with /EHsc (or /EHs which is slower), not /EHa.

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator09 [Feedback Moderator] on 11/1/2011 at 3:29 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 11/1/2011 at 2:43 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.