Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: Forbid implicit bool->int conversion

Tags:

c++

gcc

Is there any gcc flag to forbid implicit "bool -> int" conversion?

I want to get any warning with this code:

void function( int value, bool flag ) { }

int main()
{
  int a = 123;
  bool flag = true;

  //oops, a common mistake
  function( flag, a );
}
like image 950
yarrr Avatar asked Feb 25 '15 10:02

yarrr


1 Answers

As a workaround, in C++11, you may delete the other possible overloads:

template <typename T> void function(int, T) = delete;
like image 188
Jarod42 Avatar answered Sep 28 '22 12:09

Jarod42