MSVC 2019 reports errors like "identifier Native is undefined" in error list, but still builds
In detect_compiler_arch.h, line 22:
// Add to #if conditions to prevent IDE from graying out code.
#if (defined __CDT_PARSER__) || (defined __INTELLISENSE__) || \
(defined Q_CREATOR_RUN) || (defined __CLANGD__) || \
(defined GROK_ELLIPSIS_BUILD)
#define HWY_IDE 1
#else
#define HWY_IDE 0
#endif
HWY_IDE is defined when MSVC's intellisense is running. But MSVC's intellisense is not just for gathering the names of identifiers, it also populates an Error List that shows code which contains errors, even though these errors do not apply when actually building the project.
One such error is "identifier 'Native' is undefined".
"Native" is defined in base.h, line 1075:
#if HWY_HAVE_SCALAR_F16_TYPE
#if HWY_RVV_HAVE_F16_VEC || HWY_SSE2_HAVE_F16_TYPE
using Native = _Float16;
#elif HWY_NEON_HAVE_F16C
using Native = __fp16;
#else
#error "Logic error: condition should be 'all but NEON_HAVE_F16C'"
#endif
#endif // HWY_HAVE_SCALAR_F16_TYPE
It is only defined when HWY_HAVE_SCALAR_F16_TYPE is set, and either HWY_RVV_HAVE_F16_VEC or HWY_SSE2_HAVE_F16_TYPE are set. Otherwise it is undefined.
But then "Native" is used without being defined when HWY_IDE is set.
One such place is in base.h, line 1129:
#if HWY_HAVE_SCALAR_F16_OPERATORS || HWY_IDE
template <typename T, hwy::EnableIf<!IsSame<RemoveCvRef<T>, float16_t>() &&
IsConvertible<T, Native>()>* = nullptr>
This puts an error into the Error List. But it still will compile correctly because HWY_IDE is not defined when building the project for real.
Having phantom errors appearing in the Error List is confusing for a programmer, especially since those errors do not affect whether a project builds successfully. There are several possible ways to resolve the errors out of the error list:
- Don't define HWY_IDE for Intellisense. This would prevent errors from reaching the error list, but would go against the intention to prevent an IDE from graying out code.
- Disable any code that refers to "Native" and "native" when HWY_IDE is defined, but the 16-bit floating point types are unavailable.
- Make up fake definitions for "Native" and "native" that only apply when
HWY_IDEis defined and the 16-bit floating point types are unavailable. - Add a comment in the code that explains that the errors only apply to Intellisense and the Error List View, and not actual builds.