In llvm's compiler implementation tutorial (e.g. here) llvm::make_unique
is used. What is the reason they aren't using std::make_unique
? I wasn't able to find any clear documentation on this.
You can use make_unique to create a unique_ptr to an array, but you cannot use make_unique to initialize the array elements. C++ Copy. // Create a unique_ptr to an array of 5 integers. auto p = make_unique<int[]>(5); // Initialize the array. for (int i = 0; i < 5; ++i) { p[i] = i; wcout << p[i] << endl; }
The std::make_unique function was introduced in the C++14 standard. Make sure to compile with the -std=c++14 flag to be able to use this function. The object gets destroyed once p goes out of scope.
LLVM is written using C++11 conforming code while std::make_unique is a C++14 feature. So if they want make_unique
they need to implement it.
If we go to the LLVM Coding Standards the C++ Standard Versions section says:
LLVM, Clang, and LLD are currently written using C++11 conforming code, although we restrict ourselves to features which are available in the major toolchains supported as host compilers. The LLDB project is even more aggressive in the set of host compilers supported and thus uses still more features. Regardless of the supported features, code is expected to (when reasonable) be standard, portable, and modern C++11 code. We avoid unnecessary vendor-specific extensions, etc.
We can see from cppreference that std::make_unique
is a C++14 feature. If they want to use make_unique
then they can't use the std version.
We can see from a recent llvm-dev discussion that moving to C++14 is still an open subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With