C++ Logo

std-proposals

Advanced search

[std-proposals] New intrinsic type -- prvalue

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sun, 19 Oct 2025 22:12:35 +0000
If you're averse to half-baked ideas that haven't been dissected yet,
then this isn't the post for you.

About a year ago I was proposing an idea to allow a function to take a
PRvalue as a parameter, and in the past month another guy was
proposing something along similar lines.

My main aim with this only-half-thought-out proposal is that existing
code doesn't need to be changed. So let's say we have a template
function in a header file something like:

    template<typename T>
    void Func(T &&arg)
    {
        T var( std::forward<T>(arg) );
    }

Imagine if we had a function that returns a string by value as follows:

    extern string SomeLibraryFunc( int a, double b );

Now imagine if we could use a new keyword called 'prvalue' as follows:

    int main(void)
    {
        prvalue x = SomeLibraryFunction( 8, 34.4 );

        Func(x);
    }

The compiler would have its work cut out for it here. Normally when
you write a function and give it a forwarding reference for a
parameter (i.e. T&&), the compiler only has to generate two real
functions (one that takes an Lvalue, one that takes an Rvalue). On
x86_64 Linux, the address of the argument would be passed in the RDI
register. But in the above code snippet, where you see the line
"Func(x);", the compiler would have to generate an implementation of
'Func' that receives a function pointer in RDI. This function pointer
would point to a function like this:

    string CompilerGenerated000(void)
    {
        SomeLibraryFunction( 8, 34.4 );
    }

Received on 2025-10-19 22:13:04