This seems to be used in some resource files, e.g.
https://github.com/wxWidgets/wxWidgets/blob/
f3217573d7240411e7817c9d76d965b2452987a2/include/wx/msw/wx.rc#L28.
MSVC rc.exe and GNU windres both allow any value here, and silently
just truncate to uint16_t range. This just explicitly allows the
-1 value and errors out on others - the same was done for control
IDs in dialogs in
c1a67857ba0a6ba558818b589fe7c0fcc8f238ae.
Differential Revision: https://reviews.llvm.org/D76951
MENUITEM "a&bcde", 2
MENUITEM "ab&cde", 3
MENUITEM "abc&de", 4
- MENUITEM "abcd&e", 5
+ MENUITEM "abcd&e", -1
}
END
; MENU-NEXT: 0060: 61002600 62006300 64006500 00000000 |a.&.b.c.d.e.....|
; MENU-NEXT: 0070: 03006100 62002600 63006400 65000000 |..a.b.&.c.d.e...|
; MENU-NEXT: 0080: 00000400 61006200 63002600 64006500 |....a.b.c.&.d.e.|
-; MENU-NEXT: 0090: 00008000 05006100 62006300 64002600 |......a.b.c.d.&.|
+; MENU-NEXT: 0090: 00008000 FFFF6100 62006300 64002600 |......a.b.c.d.&.|
; MENU-NEXT: 00A0: 65000000 |e...|
; MENU-NEXT: )
if (auto *MenuItemPtr = dyn_cast<MenuItem>(DefPtr)) {
writeInt<uint16_t>(Flags);
- RETURN_IF_ERROR(
- checkNumberFits<uint16_t>(MenuItemPtr->Id, "MENUITEM action ID"));
+ // Some resource files use -1, i.e. UINT32_MAX, for empty menu items.
+ if (MenuItemPtr->Id != static_cast<uint32_t>(-1))
+ RETURN_IF_ERROR(
+ checkNumberFits<uint16_t>(MenuItemPtr->Id, "MENUITEM action ID"));
writeInt<uint16_t>(MenuItemPtr->Id);
RETURN_IF_ERROR(writeCString(MenuItemPtr->Name));
return Error::success();