C++0x: R-value reference

From wiki.dwarfstd.org
Revision as of 15:21, 8 January 2009 by >Kendrick.wong
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

For detail description of the feature, please refer to:



L-value reference is indicated by a single ampersand: &. (DW_TAG_reference_type)

R-value reference is indicated by two ampersands: &&.

The R-value reference can be passed into function as non-const values, thus allowing an object to modify them. This is useful for creating move semantics, so r-value can be accepted and returned without calling the copy constructor.

A&  ref1 = A();  // Error!
A&& ref2 = A();  // Ok

Both lvalue reference and rvalue reference can participate in overloading.

Proposed change to DWARF


  • New debug type is needed because r-value reference does affect overloading rules, and is of a different type to the existing l-value reference.

New DWARF tag:

DW_TAG_rvalue_reference_type 0x41 C++0x R-value reference type

Allowable attributes: (modeled after DW_TAG_reference_type)

  • DW_AT_address_class
  • DW_AT_allocated
  • DW_AT_associated
  • DW_AT_data_location
  • DW_AT_name
  • DW_AT_sibling
  • DW_AT_type


A&& ref2;

<1><  xxx>      DW_TAG_class_type
                DW_AT_name                  A
<1><  yyy>      DW_TAG_rvalue_reference_type
                DW_AT_type                  <xxx>
<1><  zzz>      DW_TAG_variable
                DW_AT_name                  ref2
                DW_AT_type                  <yyy>