[flang-commits] [PATCH] D123285: [flang] add a static assert in CheckUnitNumberInRangeImpl

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Apr 7 00:31:07 PDT 2022


jeanPerier created this revision.
jeanPerier added reviewers: schweitz, klausler.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

Add a check that CheckUnitNumberInRangeImpl is not needlessly instantiated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123285

Files:
  flang/runtime/io-api.cpp


Index: flang/runtime/io-api.cpp
===================================================================
--- flang/runtime/io-api.cpp
+++ flang/runtime/io-api.cpp
@@ -1280,6 +1280,9 @@
 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};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123285.421108.patch
Type: text/x-patch
Size: 632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220407/f27a6b9a/attachment.bin>


More information about the flang-commits mailing list