Visual Studio breaks when using curly braces instead of parenthesis

Viewed 74

I have the following wrapper of std::make_unique:

template <typename Element, typename... ArgTypes>
auto makeUnique(ArgTypes&&... arguments) {
  return std::make_unique<Element>(std::forward<ArgTypes>(arguments)...);
}

which is used this way:

template <typename F>
static auto createCustomValidator(F &&validator) {
    auto func = [validator = std::forward<F>(validator)](const int val){ return validator(seconds(val)); };
    return makeUnique<property::CustomDoubleValidator<decltype(func)>>( std::move(func) );
}

Previous versions of Visual Studio accepted the following:

return makeUnique<property::CustomDoubleValidator<decltype(func)>>{ std::move(func) };

(notice the curly braces around std::move)

Visual Studio 16.5 breaks this and can only be fixed with parenthesis instead of curly braces. Which one is correct?

1 Answers

makeUnique<property::CustomDoubleValidator<decltype(func)>> is a function, so it must be called with parentheses. The right answer is definitely parentheses.

It may be the case that previous versions of Visual Studio accepted curly braces as an extension.

Related