Skip to content

Instantly share code, notes, and snippets.

@code-disaster
Created May 5, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save code-disaster/3ff001190e1d798e5de1c5641b81dd67 to your computer and use it in GitHub Desktop.
Save code-disaster/3ff001190e1d798e5de1c5641b81dd67 to your computer and use it in GitHub Desktop.
/*
A hack found at stackoverflow.com to raise a compiler warning if a non-boolean
expression is silently converted to bool in conditional statements.
*/
struct not_a_bool {};
template< typename T >
not_a_bool ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(T /*value*/)
{
return not_a_bool();
}
bool ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(bool value);
#define if(x) if(ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(x))
#define while(x) while(ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment