From 9cfa899b87c583e0dcd20e4d35c8e9d337ee14f9 Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Mon, 11 Apr 2022 09:32:03 +0200 Subject: [PATCH] [flang] add a static assert in CheckUnitNumberInRangeImpl Add a check that CheckUnitNumberInRangeImpl is not needlessly instantiated. Differential Revision: https://reviews.llvm.org/D123285 --- flang/runtime/io-api.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index 80f4583f42d6..43e49daa1284 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -1280,6 +1280,9 @@ template static enum Iostat CheckUnitNumberInRangeImpl(INT unit, bool handleError, char *ioMsg, std::size_t ioMsgLength, const char *sourceFile, int sourceLine) { + static_assert(sizeof(INT) >= sizeof(ExternalUnit), + "only intended to be used when the INT to ExternalUnit conversion is " + "narrowing"); if (unit != static_cast(unit)) { Terminator oom{sourceFile, sourceLine}; IoErrorHandler errorHandler{oom};