Bug 1345478 - Make the PrintErrorKind::Error case explicitly unreachable in PrintSingleError; r?bbouvier draft
authorFederico Padua <federico_padua@yahoo.it>
Sun, 19 Mar 2017 19:08:13 +0100
changeset 501563 7a10fd55b5ecd3aff223838a5211a49bcca82eb5
parent 501522 8d967436d696d1f8e3fb33cf7e3d32a72457ffa6
child 549921 4a8430aec85db47f588b32eeb82d30341deb5d97
push id50028
push userbmo:federico_padua@yahoo.it
push dateMon, 20 Mar 2017 15:27:06 +0000
reviewersbbouvier
bugs1345478
milestone55.0a1
Bug 1345478 - Make the PrintErrorKind::Error case explicitly unreachable in PrintSingleError; r?bbouvier This patch explicitly calls MOZ_CRASH() in the switch case PrintErrorKind::Error that is never reached inside the function PrintSingleError in the file js/src/jscntxt.cpp. Explicitly handling all the possible cases avoids the compiler to issue warnings for them: a non handled case in the switch code that might derive from additions to the enum class PrintErrorKind can be caught at compile time rather then having a default switch case for handling it, which instead would be called at runtime. MozReview-Commit-ID: ECZlMoLvn2m
js/src/jscntxt.cpp
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -547,17 +547,17 @@ PrintSingleError(JSContext* cx, FILE* fi
                                         report->column));
         prefix = Move(tmp);
     }
 
     if (kind != PrintErrorKind::Error) {
         const char* kindPrefix = nullptr;
         switch (kind) {
           case PrintErrorKind::Error:
-            break;
+            MOZ_CRASH("unreachable");
           case PrintErrorKind::Warning:
             kindPrefix = "warning";
             break;
           case PrintErrorKind::StrictWarning:
             kindPrefix = "strict warning";
             break;
           case PrintErrorKind::Note:
             kindPrefix = "note";