C++ Logo

liaison

Advanced search

Re: [isocpp-wg14/wg21-liaison] VLA notation in parameter

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Tue, 12 Aug 2025 09:14:23 +0200
Let's get this bit out of the way separately:

On 12.08.25 08:46, Martin Uecker wrote:
> My apologies for distracting you with C array, but the fundamental
> name lookup issue affects also C++ library types:
>
> template<typename B>
> void foo(std::array<float, sizeof(B)>, B x);

There is no name lookup problem here:

template<typename B>

declares the name B to refer to an (unknown) type.

void foo(std::array<float, sizeof(B)>, B x);

The "sizeof(B)" refers to the "B" introduced by the template-head,
not to anything mentioned in the parameter that follows. For example,

template<typename B>
void foo(std::array<float, sizeof(B)>);

is also a well-formed declaration.


And "B x" declares the second parameter "x" to be of that yet-unknown
type "B".

The entirety makes up a declaration of a function template,
which is not (yet) a function. In order to turn a function
template into a function, instantiation needs to happen,
which replaces all occurrences of yet-unknown types with
known ones. This way, several different functions (one for
each combination of specific types for the set of unknown
types) can be produced from a single function template.
The compiler generates no assembly code for a function template.

Jens

Received on 2025-08-12 07:14:26