GCC Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
c++

C++: Implement LWG 3819 for references from temporaries.

C++ standard library type traits now correctly handle references constructed from prvalue temporaries, fixing a niche corner case.

This commit implements C++ Language Working Group (LWG) issue 3819, improving how type traits handle references constructed from temporary objects. Previously, the compiler incorrectly determined that a const T& could not be constructed from a prvalue U if T had a deleted move constructor, even though the move operation should be elided. A new function build_prvalue_trait_object is introduced to address this by correctly generating a prvalue for trait evaluations.

In Details

The ref_xes_from_temporary trait evaluation in cp/method.cc is updated to align with LWG 3819. Instead of always using build_trait_object which yields an xvalue, it now uses build_prvalue_trait_object when evaluating VAL<T> to correctly model the standard's requirement that VAL<T> is initially a prvalue. This resolves cases where a deleted move constructor would incorrectly inhibit a valid reference binding from a prvalue temporary.

For Context
LWG 3819
A specific issue (number 3819) from the C++ Language Working Group that addresses the correct behavior of type traits concerning references and temporary objects.
Type Trait
Metaprogramming facilities in C++ (e.g., std::is_constructible, std::reference_constructs_from_temporary_v) that query properties of types at compile time.
prvalue
A pure rvalue in C++, typically resulting from an expression like a literal or a function call returning by value.
xvalue
An expiring value in C++, often resulting from a cast to an rvalue reference, indicating an object that is expiring but can still be moved from.
move constructor
A constructor that initializes a new object by transferring ownership of resources from an expiring object (rvalue).
elision
Compiler optimization that avoids unnecessary copy or move operations, such as eliminating temporary objects or move constructor calls.
Filed Under: c++languagetype traitsstandard