How can I get MSVC to warn or fail if a switch error occurs?

I would like to receive a warning / error if one of my switch statements has a case that does not interrupt. Is it possible?

switch (i){
case 1:
    cout << "one";
//forgot to break here, I want to be warned about this
case 2:
    cout << "two";
    break;
}

A similar Clang feature was discussed at the upcoming 2012 conference, but I need it for MSVC2013 http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Clang-Defending-C-from-Murphy-s-Million-Monkeys

Ideally, I would like to receive a warning if two consecutive bodies are not separated by a gap, so the above example will fail, but it will not:

switch (i){
case 1:
    cout << "one";
    break;
case 2:
case 3:
    cout << "not one";
    break;
}
+4
source share
1

.

switch , break, case.

, , , - if.

-2

Source: https://habr.com/ru/post/1527904/


All Articles