The following code produces an “undefined reference” error in C++14 mode, and has no issue in c++17 with latest Clang (same for gcc, but works in both cases with VS2017):
#include <memory>
struct S
{
static constexpr int i = 42;
};
int main()
{
std::make_unique<int>(S::i); // undefined reference in C++14, no issue in C++17
}
What is changed between two standard revisions related to this issue? Does VS have correct behavior for this code in C++14 according standard?
Adding a definition for S::i
fixes the issue for any compiler/standard.
My question is mostly of make_unique
behavior, why definition is needed? For instance, I can use std::unique_ptr<int>(new int(S::i))
without definition of S::i
.
Also, suggested duplicate doesn’t answer why Visual Studio accepts code in C++14 mode.