Since I lost track of the C++11 and C++14 (not out yet I suppose) changes, I was wondering if the following is possible in C++ or if there is any plan to make something like this working: I need a way to query a class or a function whether it uses a variable or not. If not, I should be able to add a variable used in a higher scope (either from a caller function or some code that instantiates that class).
I can do all this at runtime but it has a performance penalty I can't afford. Writing my own compiler sounds heavy.
The canonical solution to your real problem is NOT a variable which you somehow query.
I'd personally use a template which the user may or may not instantiate. That's quite easy to discover. It's also an existing mechanism which works in C++98, 03 11 and 14.
Remember that under the ordinary C++ compilation model, you can't query at your compile time whether another function will use a variable when it is compiled. That would take a time machine.