Created
December 7, 2012 01:16
-
-
Save simonlynen/4229928 to your computer and use it in GitHub Desktop.
TMP to echo a compile time constant during compilation as a warning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//output a compile time constant | |
template<size_t size> | |
struct overflow{ operator char() { return size + 999999; } }; //always overflow | |
template<int VALUE> | |
void echoCompileTimeConstant() | |
{ | |
char(overflow<VALUE>()); | |
} | |
Usage: | |
enum{ | |
val = 4 | |
} | |
msf_tmp::echoCompileTimeConstant<val>(); | |
Outputs: | |
warning: overflow in implicit constant conversion [-Woverflow] | |
instantiated from ‘void msf_tmp::echoCompileTimeConstant() [with int VALUE = 4]’ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment