[flang] add a static assert in CheckUnitNumberInRangeImpl

Add a check that CheckUnitNumberInRangeImpl is not needlessly instantiated.

Differential Revision: https://reviews.llvm.org/D123285
This commit is contained in:
Jean Perier 2022-04-11 09:32:03 +02:00
parent e995526e66
commit 9cfa899b87
1 changed files with 3 additions and 0 deletions

View File

@ -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};