Monday 21 October 2013

New year, new challenges, new goddamn errors...

Yesterday I was doing some stuff to my personal project when I stumbled upon some freaking compile error which made no sense in the given context. Well, the thing is, I started this blog as my personal vault to keep things that I should remember or I was really proud of (not that I am not proud of anything - number of posts is a lie!) and my recent waste of time was a precious experience I want to avoid in the future. It is always your fault is a mantra that a good programmer should be aware of and embrace it but don't fool yourself into thinking that everything around us is perfect because it is not.
I wrote a post on linker error last time (yeah, a year ago, I know) and yet I made exactly the same mistake a few weeks ago when I was setting up solution for a new project. Forgetting such things is really bad, in fact it is so bad that it deserves its own, even worse verb like unremebering. But this time was different, it was even more frustrating because as it turns out it was yet another compiler error. The following fails to compile on both VC2012 with Nov 2012 CTP C++ compiler and (at least for me) on VC2013 Express RTM:

template<typename T> Foo* Func() { return nullptr; }

template<typename... TArgs>
void SomeFunc() {
   Foo* data[] = {
     Func<TArgs>()..., // <- expand the pack into array but calling Func for each type
     nullptr
   };
}
The error message I got was either:
cannot allocate an array of constant size 0

or:
error C4789: buffer 'data' of size 8 bytes will be overrun; -4 bytes will be written starting at offset 8

The first error message is as clear as it gets but seriously looking at the code (which was obviously a tad different). The last element seemed to be ignored when the parameter pack was empty ( SomeFunc<>(); call) I lost 3 hours rearranging stuff, wrapping/unwrapping stuff, trying to search on the net if that was even legal C++11 and finally I asked a question on stackoverflow. Well it turned out that the code was perfectly fine, just VC++ gives a shit about stupid stuff like standard I suppose. At first I thought ok I was using CTP and it was my own fault, but it failed on VC13 too so I went digging and found a ticket on microsoft connect about suspiciously similar bug reported back in the 2012 - they responsted that they acknowledge the bug but do not plan to fix it, although they might change their decision in the future - how cute. Lesson learned - always take a second opinion on things that are at least suspicious - prefferably from another compiler, which is really easy and fast check - as there is a slight chance that it was not your bug! I wasted another hour looking for a workaround with a twisted smile on my face.

Now TL;DR version of why I haven't written anything in the past year, or even longer I guess: got job in gamedev industry, no time, getting my new flat done, working on own engine etc. Hopefully I will have more time now!

No comments:

Post a Comment