Compilation with gcc 8.1 fails due to missing explicit cast on unique_ptr
Functional impact
It is not possible to build dxc on systems that use gcc 8.1 or newer (such as Debian testing).
Minimal repro steps
Attempt compilation with cmake 3.12.3 and gcc 8.2.0, although the issue is also present in gcc 8.1.
Expected result
Compilation succeeds.
Actual result
The following compilation error is thrown:
[ 24%] Building CXX object lib/HLSL/CMakeFiles/LLVMHLSL.dir/DxilLinker.cpp.o
In file included from /dxc/include/llvm/Transforms/Utils/Cloning.h:24,
from /dxc/lib/HLSL/DxilLinker.cpp:26:
/dxc/include/llvm/IR/ValueMap.h: In member function ‘bool llvm::ValueMap<KeyT, ValueT, Config>::hasMD() const’:
/dxc/include/llvm/IR/ValueMap.h:102:31: error: cannot convert ‘const std::unique_ptr<llvm::DenseMap<const llvm::Metadata*, llvm::TrackingMDRef> >’ to ‘bool’ in return
bool hasMD() const { return MDMap; }
Title
Compilation with gcc 8.1 fails due to missing explicit cast on unique_ptr
Functional impact
It is not possible to build dxc on systems that use gcc 8.1 or newer (such as Debian testing).
Minimal repro steps
Attempt compilation with cmake 3.12.3 and gcc 8.2.0, although the issue is also present in gcc 8.1.
Expected result
Compilation succeeds.
Actual result
The following compilation error is thrown:
Further technical details
This is a known issue that has been reported and fixed elsewhere: https://github.com/digego/extempore/issues/318
The C++ standard specifies
operator bool
onunique_ptr
as being explicit, so this is clearly a bug in the LLVM source code: https://en.cppreference.com/w/cpp/memory/unique_ptr/operator_boolIt can be fixed by adding an explicit cast:
or: