Visual C++ 2005 compiler bugs

Back to Blog

Here are some of the bugs I have found in the Visual C++ 2005 compiler.

Inner class

template <typename T>
class A
{
public:
    class B
    {
    public:
        class A
        {
        public:
            A();
        };
    };
};

int main()
{
    return 0;
}

Iterator splice

#include <list>

int main()
{
   std::list<int> a(9, 1);
   a.push_back(4);
   std::list<int> b(1, 2);

   std::list<int>::iterator valuesBegin(a.begin());
   std::list<int>::iterator valuesEnd(a.end());
   --valuesEnd;

   std::list<int>::iterator newValuesEnd(b.end());

   // This should not have any effect on iterators.

   b.splice(newValuesEnd, a, valuesBegin, valuesEnd);

   // Checked iterator assertion (a bug).

   valuesBegin != newValuesEnd;

   // Possible another bug:
   // This works for equivalent allocators,
   // how about non-equivalent allocators?

   std::list<int>::iterator iter(valuesBegin);
   while(iter != newValuesEnd)
   {
      *iter = 3;
      ++iter;
   }

   return 0;
}

Iterator swap

#include <list>

using namespace std; 

int main()
{
   // The same fatal errors are present with
   // all of the stl containers.

   typedef list<int> Container;

   Container a;
   Container b;

   // It doesn't matter whether there is data
   // in the containers or not.

   //a.push_back(1);
   //b.push_back(1);

   {
      // Case 1:
      // Comparing iterators from different containers
      // gives a fatal error. Sounds rational, although
      // the error diagnostics could be better.

      // Fatal error
      //a.begin() == b.begin();
   }

   {
      // Case 2:
      // The following is guaranteed to be
      // legal by the standard.

      Container::iterator i(a.begin());
      a.swap(b);
      Container::iterator j(b.begin());

      // Fatal error
      i == j;
   }

   return 0;
}

Template

// The bug is inconsistent, there seems to be no
// strict logic.

namespace MyNames
{

    template <typename S, typename T>
    struct MyPair
    {
    };

}

template <typename T>
class MyClass
{
public:
    class A
    {
    };

    MyNames::MyPair<A, int> f();
    MyNames::MyPair<A, A> g();
    MyNames::MyPair<A, int> h();
};

template <typename T>
MyNames::MyPair<typename MyClass<T>::A, int>
MyClass<T>::f()
{
    return MyNames::MyPair<A, int>();
}

template <typename T>
MyNames::MyPair<typename MyClass<T>::A, typename MyClass<T>::A> 
MyClass<T>::g()
{
    return MyNames::MyPair<A, A>();
}

template <typename T>
MyNames::MyPair<typename MyClass<T>::A, int> 
MyClass<T>::h()
{
    return MyNames::MyPair<A, int>();
}

int main()
{
    return 0;
}