C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] (SC22WG14.18841) [Fwd: sudo buffer overlow]

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Sat, 30 Jan 2021 16:10:21 +0000
Am Samstag, den 30.01.2021, 11:02 -0500 schrieb Bjarne Stroustrup via Liaison:
> On 1/30/2021 10:18 AM, Arvid Norberg via Liaison wrote:
> > int const len = 10;
> >
> > void m(int n) {
> > int a[n]; // VLA
> > int b[len]; // normal array
> >
> > std::array<char, sizeof(a)> a2; // ERROR: sizeof() is a runtime
> > value on VLAs
> > std::array<char, sizeof(b)> b2; // OK
> >
> > std::array<decltype(a), 5> a3; // ERROR: decltype() on VLA
> > std::array<decltype(b), 5> b3; // OK
> >
> > v(a); // ERROR: no matching function for call to 'v(int [n])'
> > v(b); // OK
> >
> > t(a); // ERROR: variable-sized array type 'long int' is not a valid
> > template argument
> > t(b); // OK
> >
> > u(a); // ERROR: could not convert '(int*)(& a)' from 'int*' to
> > 'std::span<int>'
> > u(b); // OK
> > }
>
>
> Examples like this featured prominently in the discussions. Many was
> very uneasy with the idea that "int a[n];" could have different types
> based on the definition of n.

In C

int n = 4;
int a[n];
int a[4];

have compatible types, so would be treated as equivalent with
regard to the type system.

Best,
Martin


> An other area of unease/dislike was the way VLAs were used in function
> parameters. I don't recall details, but those might have been recorded
> somewhere.

Received on 2021-01-30 10:10:27