Skip to content

Instantly share code, notes, and snippets.

@simonlynen
Created December 7, 2012 01:16
Show Gist options
  • Save simonlynen/4229928 to your computer and use it in GitHub Desktop.
Save simonlynen/4229928 to your computer and use it in GitHub Desktop.
TMP to echo a compile time constant during compilation as a warning
//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