Linear array syntax attributes

When I use array literals, I see strange behavior in different compilers.

The first problem I encounter is when I have such a program:

void f(int*)
{
}

int main()
{
    using T = int[];
    f(T{1, 2, 3});
}

In Clang 3.5, this compiles fine, but on g ++ 4.9 it gives an error:

source_file.cpp: In function ‘int main()’:
source_file.cpp:8:17: error: taking address of temporary array
     f(T{1, 2, 3});

In VC ++, it gives an error:

Process exit code is not 0: 255

So strange.

If I make it Tequal int[3]instead int[], it will compile in VC ++ , but it still gives the same error in g ++.

Also, if I changed the code to:

using T = int[];
int* x = T{1, 2, 3};

then clang gives an error similar to g ++.

Which compiler is right?


, g++, f be int (&&)[3], V++ .

+4
1

. [expr.type.conv]/3, ( GCC), , :

lvalue rvalue " N T" " " of T " prvalue " T ". .

+4

All Articles