Have you ever written lots of functions without compiling. Then in your ( lets say loop() ) function you use a couple of the functions and compile. Everything goes well so you add in the remainder functions and suddenly you get a syntax/compile error. Even though the function was defined with the error previously, because it wasn't referenced it didn't pass through the compiler.
In reference to __builtin_constant_p, it is seeing 'a' before it has seen the remainder of the function. I think this is hard/impossible to get around.
This is just a thought,
If 'foo' was a type based template, you could create a forward declaration of 'foo'. You can now but it would require a forward declaration for every possible value of 't', which might not be such a bad idea for a range of possible 't'.
But I still don't think you will have luck as the compiler is linear, it still can't guarantee 'a' will not get assigned a value on the next line of code. Even though optimisations can pass many times, __builtin_constant_p is evaluated once.