mardi 5 décembre 2017

Can I detect at compile time function arguments that are compile-time constants

Can I detect at compile time whether function arguments are compile-time constants?

For example a function print(int i) that can print "constant 5" if called as print(5) but "non-constant 5" if called as print(i) where i is some non-constant variable.

Macro tricks are OK, template meta-programming is OK. Ideally it is portable, but solutions that are compiler-specific are better than nothing.

It's OK if there are "false negatives" - i.e., if constant values are sometimes detected as non-constant (e.g., when certain optimizations are disabled).

Bonus points if the solution can detect when constant values are indirectly passed to the function (e.g., when a constant value is passed to an intermediate function that calls print and which is subsequently inlined exposing the constant to print). This last behavior is evidently optimization dependent.

Aucun commentaire:

Enregistrer un commentaire