STL containers require the stored values to be copy constructible and assignable. const T is obviously not an assignable type for any T, but I tried to use it (just being curious) and found out that it compiles and, moreover, behaves as an assignable type.
vector<const int> v(1);
v[0] = 17;
This successfully runs in Visual Studio 2008 and assigns v[0] to 17.
This is not a bug in the implementation as others have suggested.
Violating the requirements of a C++ Standard Library facility does not render your program ill-formed, it yields undefined behavior.
You have violated the requirement that the value type stored in a container must be copy constructible and assignable (
const
types are not assignable, obviously), so your program exhibits undefined behavior.The applicable language from the C++ Standard can be found in C++03 17.4.3.6 [lib.res.on.functions]:
The Visual C++ Standard Library implementation may do anything with this code, including silently removing or ignoring the const-qualification, and it is still standards-conforming.