C++ Logo

liaison

Advanced search

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

From: Bjarne Stroustrup <bjarne_at_[hidden]>
Date: Sat, 30 Jan 2021 11:02:37 -0500
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.

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:02:41