Hacker News new | ask | show | jobs
by int_19h 3436 days ago
ะก++ takes it all the way to 11 with templates. Here's a program that is parsed differently depending on whether pointers are 32-bit or 64-bit:

    template<size_t N = sizeof(void*)> struct a;

    template<> struct a<4> {
        enum { b };
    };

    template<> struct a<8> {
        template<int> struct b {};
    };

    enum { c, d };

    int main() {
        a<>::b<c>d;
        d;
    }
Depending on which instantiation is used, the first line of main is either a variable declaration, or two operators < and > applied in sequence.

This is especially fun to deal with for C++ IDEs that support semantic highlighting (i.e. typenames are in a different color etc). If I remember correctly, the first one that could handle this right was VS 2012 - it only took 14 years after ISO C++ standard was released...