Declaring an empty C ++ array with an aggregate initializer

In C ++, unlike C, an empty array T name[]is illegal,

the declared type is an "array of unknown boundary T", which is a kind of incomplete type.

However, it is legal when

used in aggregate initializer declaration

like T name[] = {val1, val2, ...}where the array is allocated with the number of elements in the list of initializers.

What is the expected behavior when the aggregate initializer is empty? T name[] = {}

I tested g ++ (version 4.8.4) and clang (version 3.4), none of which give any errors or warnings and seem to highlight 1 element. Is this a specific behavior? Documentation?

int a[] = {};
int b[] = {};

Results in:

a[0] -> 0x7ffc3de28dd8
a[1] -> 0x7ffc3de28ddc
b[0] -> 0x7ffc3de28ddc
b[1] -> 0x7ffc3de28de0
+4
2

[8.5.1/5] ():

{} initializer .

. [footnote/105]:

, , , ++ .

UB.


, :

template<int N>
void f(int(&)[N]) { }

int main() {
    int v[] = {42};
    f(v);
}

, :

int v[] = {};

GCC.

+2

++ 1.8.6 (++ 14):

, , , , ; , .4

, .

+2

All Articles