Environment
Operating System: Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35223 for x86
Version / Commit SHA: SHA: [63a052f](
Other: compiled with /std:c++20 /permissive- (probably irrelevant)
Describe the bug
When using evalFirstCached() in ValueAccessor.h, MSVC emits the following warning: (see here)
5>[..]\openvdb\tree\ValueAccessor.h(1002,1): warning C4702: unreachable code
To Reproduce
Steps to reproduce the behavior:
- Include the header
ValueAccessor.h without ignoring warnings
- Use
evalFirstCached() such that Idx is less than template parameter Start
alternatively, it must be greater than NumCacheLevels+1
Expected behavior
The compiler does not emit a warning
Additional context
The warning is triggered when any of the two constexpr-ifs conditions evaluates true.
In this case, the function is left early with a return, but the code will still continue to contain return this->isHashed<NodeType>(xyz); which indeed is unreachable for each such instantiation of the function template.
To fix this, change the code to this: (note the added else statements)
return this->evalFirstPred([&](const auto Idx) -> bool
{
if constexpr(Idx < Start) return false;
else if constexpr(Idx > NumCacheLevels+1) return false;
else
{
using NodeType = typename NodeLevelList::template Get<Idx>;
return this->isHashed<NodeType>(xyz);
}
}, op);
Now, the culprit line is only contained in instantiations when both constexpr-ifs conditions evaluate false.
Environment
Operating System: Microsoft (R) C/C++ Optimizing Compiler Version 19.44.35223 for x86
Version / Commit SHA: SHA: [63a052f](
Other: compiled with /std:c++20 /permissive- (probably irrelevant)
Describe the bug
When using
evalFirstCached()inValueAccessor.h, MSVC emits the following warning: (see here)To Reproduce
Steps to reproduce the behavior:
ValueAccessor.hwithout ignoring warningsevalFirstCached()such thatIdxis less than template parameterStartalternatively, it must be greater than
NumCacheLevels+1Expected behavior
The compiler does not emit a warning
Additional context
The warning is triggered when any of the two constexpr-ifs conditions evaluates true.
In this case, the function is left early with a return, but the code will still continue to contain
return this->isHashed<NodeType>(xyz);which indeed is unreachable for each such instantiation of the function template.To fix this, change the code to this: (note the added
elsestatements)Now, the culprit line is only contained in instantiations when both constexpr-ifs conditions evaluate false.