Fix the following Bug:
https://llvm.org/bugs/show_bug.cgi?id=28366
This patch teaches the constant expression evaluator to search the frame stack for a local variable (instead of assuming a local variable is on the current frame).
This has the following benefits:
- if the local variable from an enclosing scope was an error during parsing/instantiation - it remains an error (instead of a compiler crash) during constant expression evaluation
- a local variable that is a constant expression from an enclosing scope is now evaluatable
Additionally, fix SemaTemplateInstantiateDecl so that when it instantiates the enable_if attribute it uses the instantiated declaration (instead of the template) when evaluating the condition (so that the instantiated param's decl context is correctly found). This was done to fix the following regression:
template <typename T> T templatedBar(T m) attribute((enable_if(m > 0, ""))) { return T(); }
This is talking too much about the what and not enough about the why. "We expect to find a value for a local variable in the current frame, unless the variable was actually declared in a lexically-enclosing context." or something like that?