3

example:

#include <string>
#include <array>

template<class T, class...Args>
auto make_array(Args&&...args) -> std::array<T, sizeof...(Args)>
{
    return std::array<T, sizeof...(Args)> {
        T(std::forward<Args>(args))...
    };
}

int main()
{
  auto a = make_array<std::string>("hello", "world");
}

GCC 5.3 is perfectly happy with it, even with -Wpedantic

clang reports a warning:

warning: suggest braces around initialization of subobject [-Wmissing-braces]
        T(std::forward<Args>(args))...
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
        {                          }

If I follow clang's autocorrect advice, it results in uncompilable code.

clang version:

Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix

For now, I have disabled warnings with a localised #pragma. But this is deeply unsatisfactory:

template<class T, class...Args>
auto make_array(Args&&...args) -> std::array<T, sizeof...(Args)>
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-braces"
    return std::array<T, sizeof...(Args)> {
        T(std::forward<Args>(args))...
    };
#pragma clang diagnostic pop
}

@n.m. this is not a duplicate. It's a specific question on how to remove the warning. The advice given by clang's autocorrect is wrong.

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142

0 Answers0