5

Please consider this sample C++20 program:

#include <vector>
#include <iostream>

auto make_vector( auto v[2] ) { return std::vector{v[0], v[1]}; }

int main()
{
    int x[2] = {1, 2};
    auto v = make_vector( x );
    std::cout << v[0] << ' ' << v[1] << '\n';
}

Both GCC and Clang accept it (https://gcc.godbolt.org/z/jKT7GjMK6)

However the latest Visual Studio 2019 16.10.3 with /std:c++latest option rejects it:

error C3318: 'auto [2]': an array cannot have an element type that contains 'auto'

Is it a bug or limitation of MSVC, or this code is not required to work in C++20?

Fedor
  • 17,146
  • 13
  • 40
  • 131
  • 4
    [c++ - Generic lambdas with statically sized arrays as arguments](https://stackoverflow.com/questions/45902923/generic-lambdas-with-statically-sized-arrays-as-arguments/45903381) – Pixelchemist Jul 17 '21 at 12:01
  • 3
    @Pixelchemist - Thew rules *have changed* in C++20. And given the other question is explicitly C++14, a C++20 answer doesn't belong there. A dupe it is not. – StoryTeller - Unslander Monica Jul 17 '21 at 12:21
  • 1
    @StoryTeller-UnslanderMonica I didn't say so nor did I (down/close) vote accordingly. I just provided this link for reference. – Pixelchemist Jul 17 '21 at 12:23
  • 4
    I think [cwg 2397](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2386r0.html#2397) (accepted last month) made this valid, but I'm not sure. – cpplearner Jul 17 '21 at 12:33
  • It looks like MSVC bug, MSVC accepts ```auto *``` parameter: https://gcc.godbolt.org/z/hcq43xsxb –  Jul 20 '21 at 10:03

0 Answers0