[flang-commits] [flang] 9cfa899 - [flang] add a static assert in CheckUnitNumberInRangeImpl
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Mon Apr 11 00:33:20 PDT 2022
Author: Jean Perier
Date: 2022-04-11T09:32:52+02:00
New Revision: 9cfa899b87c583e0dcd20e4d35c8e9d337ee14f9
URL: https://github.com/llvm/llvm-project/commit/9cfa899b87c583e0dcd20e4d35c8e9d337ee14f9
DIFF: https://github.com/llvm/llvm-project/commit/9cfa899b87c583e0dcd20e4d35c8e9d337ee14f9.diff
LOG: [flang] add a static assert in CheckUnitNumberInRangeImpl
Add a check that CheckUnitNumberInRangeImpl is not needlessly instantiated.
Differential Revision: https://reviews.llvm.org/D123285
Added:
Modified:
flang/runtime/io-api.cpp
Removed:
################################################################################
diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp
index 80f4583f42d63..43e49daa1284b 100644
--- a/flang/runtime/io-api.cpp
+++ b/flang/runtime/io-api.cpp
@@ -1280,6 +1280,9 @@ template <typename INT>
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<ExternalUnit>(unit)) {
Terminator oom{sourceFile, sourceLine};
IoErrorHandler errorHandler{oom};
More information about the flang-commits
mailing list