Fix link error for certain usages of [D]CHECK_*
Background: as part of bug 1066670, we're removing usage of Xlib and switching to our own X11 protocol bindings. In Xlib, constants are usually defined as macros: #define GenericEvent 35 Our approach is different: struct GeGenericEvent { static constexpr uint8_t opcode = 35; }; There are many instances of the following snippet: DCHECK_EQ(event.type, GenericEvent); which now need to be changed to: DCHECK_EQ(event.type, GeGenericEvent::opcode); However, this causes a subtle link failure: ld.lld: error: undefined symbol: x11::GeGenericEvent::opcode This is because CheckEqImpl's parameters are passed as const&, but the static constexpr value doesn't have an address. Alternatives considered: * Change uint8_t to int to get the existing int overload of CheckEqImpl. We want to avoid this because using int would imply there are more opcodes than can actually exist in the protocol. * Change *::opcode to be non-constexpr static, defined in source file. This won't work because it's common to switch() over the opcode, and that won't work unless the cases are constexpr values. * Create a separate source file that provides redundant definitions of these constants. This is a hack. This CL extends the existing int-int overload meant to solve this issue to any fundamental type. BUG=1066670 R=thestig Change-Id: If62c845cf590cca484e13cf482a67ef4cdd51cbd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2236220 Commit-Queue: Thomas Anderson <thomasanderson@chromium.org> Reviewed-by:Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#776254}
Showing
Please register or sign in to comment