Visual Studio 2005 SP1
Yesterday, Microsoft released the Visual Studio 2005 SP 1. Unfortunately, it seems a rather serious bug has crept in - read on for details, especially if you are an active Qt user.First of all, there is no real changelog yet which describes all fixes, just a short release notes document. No idea when the full changelog will come online - for a company like Microsoft, it should be possible to release the changelog along with the service pack. In the release notes, take a look at “Recent versions of the Qt library source give errors on compilation.” Seems they have introduced a bug into the compiler, and provided the wrong workaround for it, too … The affected code - which compiles fine with the previous version and with GCC 4.1.2 (prerelease) is:
template <class T> class A
{
public:
typedef int N_A;
};
template <class T> class B : public A<T>
{
public: typename A<T>::N_A test();
};
template <class T> typename A<T>::N_A B<T>::test() /* 1 */
{
return 0;
}
I can confirm that it does not work with Visual Studio 2005 SP1. The suggested workaround for this perfectly valid code is to introduce a typedef
for A<T>::N_A
. However, this workaround is flawed. Instead of doing a typedef
you can rely on inheritance. After all, B
is derived from A
and inherits the typedef
just as well, so instead of typedef’ing you can write:
template typename B::N_A B::test() /* 1 */
{
return 0;
}
No idea why Microsoft is introducing the additional typedef which does nothing new. My fix works with the new compiler and is less intrusive than the typedef’ing suggested by Microsoft (moreover, you don’t have to sync both typedefs!). Unfortunately, it seems that Qt will be affected by this bug. As Qt is used quite widely, I cannot understand how this bug may have slipped through the QA and become a known issue as it is likely to break a lot of code written against Qt. As long as there is no clear changelog and/or hotfix for this issue, I don’t recommend updating to SP1. I’m also rather curious to see what Trolltech will say about this issue.