Add default case to switch statements

When compiling with the -Wswitch-default flag, the compiler
spits warnings for the moc generated files.
In certain development environments (e.g. where MISRA rules
have to be followed) every switch statement needs to have a
default case. Unfortunately the moc generated files contain
switch statements without default case. This patch adds a
default statement to all switch statements that are generated
by the moc compiler.

Change-Id: I8f3d81e3463fce4d3abf2ea5d0fa8727a7d9ba2e
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Kurt Pattyn 2014-04-15 09:57:15 +02:00 committed by The Qt Project
parent a006ede6e7
commit beb7258a56
1 changed files with 9 additions and 0 deletions

View File

@ -983,6 +983,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s; break;\n",
propindex, p.type.constData(), prefix.constData(), p.member.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
@ -1031,6 +1032,7 @@ void Generator::generateMetacall()
fprintf(out, " break;\n");
}
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
@ -1054,6 +1056,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: %s%s; break;\n",
propindex, prefix.constData(), p.reset.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1072,6 +1075,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *_b = %s; break;\n",
propindex, p.designable.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1090,6 +1094,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *_b = %s; break;\n",
propindex, p.scriptable.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1108,6 +1113,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *_b = %s; break;\n",
propindex, p.stored.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1126,6 +1132,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *_b = %s; break;\n",
propindex, p.editable.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1145,6 +1152,7 @@ void Generator::generateMetacall()
fprintf(out, " case %d: *_b = %s; break;\n",
propindex, p.user.constData());
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
}
fprintf(out,
@ -1226,6 +1234,7 @@ void Generator::generateStaticMetacall()
fprintf(out, ");\n");
fprintf(out, " if (_a[0]) *reinterpret_cast<QObject**>(_a[0]) = _r; } break;\n");
}
fprintf(out, " default: break;\n");
fprintf(out, " }\n");
fprintf(out, " }");
needElse = true;