From b42c6ea281add0d5ad3bd2bec52742353c718603 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sat, 3 Oct 2020 16:26:09 +0330 Subject: [PATCH] LibIPC: Make IPC::encode() and ::decode() fail at compiletime when used This would previously fail at runtime, and it would have zero indication of what exactly went wrong. Also adds `AK::DependentFalse', which is a...dependent false. --- AK/StdLibExtras.h | 4 ++++ Libraries/LibIPC/Decoder.h | 3 ++- Libraries/LibIPC/Encoder.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index c47066df4a..e8e02703ee 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -504,6 +504,9 @@ using CopyConst = template using Void = void; +template +inline constexpr auto DependentFalse = false; + } using AK::AddConst; @@ -512,6 +515,7 @@ using AK::ceil_div; using AK::clamp; using AK::Conditional; using AK::declval; +using AK::DependentFalse; using AK::exchange; using AK::forward; using AK::is_trivial; diff --git a/Libraries/LibIPC/Decoder.h b/Libraries/LibIPC/Decoder.h index 1f366f5d3f..37c3d6a848 100644 --- a/Libraries/LibIPC/Decoder.h +++ b/Libraries/LibIPC/Decoder.h @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -37,8 +38,8 @@ namespace IPC { template inline bool decode(Decoder&, T&) { + static_assert(DependentFalse, "Base IPC::decoder() instantiated"); ASSERT_NOT_REACHED(); - return false; } class Decoder { diff --git a/Libraries/LibIPC/Encoder.h b/Libraries/LibIPC/Encoder.h index da88d889ac..b5869c5a82 100644 --- a/Libraries/LibIPC/Encoder.h +++ b/Libraries/LibIPC/Encoder.h @@ -34,6 +34,7 @@ namespace IPC { template bool encode(Encoder&, T&) { + static_assert(DependentFalse, "Base IPC::encode() was instantiated"); ASSERT_NOT_REACHED(); }