[Lldb-commits] [lldb] r369614 - [FormatManager] Add static_assert to keep formats in sync.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 21 19:56:01 PDT 2019


Author: jdevlieghere
Date: Wed Aug 21 19:56:00 2019
New Revision: 369614

URL: http://llvm.org/viewvc/llvm-project?rev=369614&view=rev
Log:
[FormatManager] Add static_assert to keep formats in sync.

This adds a static assert that ensures that there's a format info entry
for every format enum value. This should prevent others from making the
same mistake I made and Jason kindly fixed in r369611. (Thanks!)

Modified:
    lldb/trunk/source/DataFormatters/FormatManager.cpp

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=369614&r1=369613&r2=369614&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Wed Aug 21 19:56:00 2019
@@ -30,7 +30,7 @@ struct FormatInfo {
                            // current format
 };
 
-static FormatInfo g_format_infos[] = {
+static constexpr FormatInfo g_format_infos[] = {
     {eFormatDefault, '\0', "default"},
     {eFormatBoolean, 'B', "boolean"},
     {eFormatBinary, 'b', "binary"},
@@ -72,6 +72,10 @@ static FormatInfo g_format_infos[] = {
     {eFormatInstruction, 'i', "instruction"},
     {eFormatVoid, 'v', "void"}};
 
+static_assert((sizeof(g_format_infos) / sizeof(g_format_infos[0])) ==
+                  kNumFormats,
+              "All formats must have a corresponding info entry.");
+
 static uint32_t g_num_format_infos = llvm::array_lengthof(g_format_infos);
 
 static bool GetFormatFromFormatChar(char format_char, Format &format) {




More information about the lldb-commits mailing list