One of our projects produces a lot of warnings along the lines of
NVC++-W-0277-Cannot inline function _Zan4EnumS_ - data type mismatch (test.cpp: 8)
which apparently are difficult to suppress, at least --diag_suppress=277 doesn’t work.
A small reproducer is
enum struct Enum : long { value };
inline Enum operator&(Enum lhs, Enum rhs) {
return Enum::value;
}
int main() {
auto x = Enum::value & Enum::value;
}
which produces
$ nvc++ -O2 test.cpp
NVC++-W-0277-Cannot inline function _Zan4EnumS_ - data type mismatch (test.cpp: 8)
NVC++-W-0277-Cannot inline function _Zan4EnumS_ - data type mismatch (test.cpp: 8)
NVC++/x86-64 Linux 21.9-0: compilation completed with warnings
If the underlying type is changed from long to int or unsigned, the warning disappears.
As far as I know this is “only” annoying, but it would be great if it could be fixed or suppressed somehow.
Hmm, we should have added support for autoinlineing of enum types a few releases ago, so this looks like a case that we may have missed. I’ve sent to engineering to review. The code will still be functional, just missing an optimization.
As for error suppression, “–diag_suppress” is only available for the front-end compiler. The back-end compiler is only able to suppress all warnings via “-w” as opposed to individual warnings.
Yes, and it may be awhile given it’s just a warning. Also it’s only the auto-inliner (i.e. implicit inlining with the “inline” keyword). The routine will inline with the “-Minline” flag. So as a work around compile with: