Overview

The new keyword constexpr allows the user to guarantee that a data, function or object constructor is a compile-time constant. Standard allows floating-point constant expression as well. The constexpr is a new declaration specifier (not a new type) and it does not affect overloading rules. A variable or data member declared with constexpr behaves as if it was declared with const. Constant expression function must be defined before it is used, thus disallowing recursive function calls. Function parameter cannot be declared constexpr. A constant-expression function may be called with non-constant expressions, in that case there is no requirement that the resulting value be evaluated at compile-time. A function or a constructor declared with constexpr is implicitly inline. A constant-expression constructor may be invoked with non-constant expression arguments, the resulting initialization may then be dynamic.

Proposed change to DWARF

To identify if a variable, function or object constructor can be evaluated as compile-time constants.

(Optional) To capture the value of the constant-expression.

New DWARF attribute:

DW_AT_const_expr

0x69

flag

A compile-time constant expression

3.3.8.1: Abstract Instances

In C++, a function or a constructor declared with constexpr is implicitly inline. This abstract inline instance is represented by a debugging information entry with the tag DW_TAG_subprogram. Such entry has a DW_AT_inline attribute whose value is DW_INL_inlined.

3.3.8.2: Concrete Inlined Instances

Each inline subroutine entry may contain a DW_AT_const_expr attribute whose value is a flag which indicates that the subroutine can be evaluated as a compile-time constant. Such entries may have a DW_AT_const_value attribute, whose value may be a string or any of the constant data or data block forms, as appropriate for the representation of the subroutine's return value. The value of this attribute is the actual return value of the subroutine, represented as it would be on the target architecture.

In C++, if a function or a constructor declared with constexpr is called with constant-expressions, then this concrete inlined instance has a DW_AT_const_expr attribute, as well as a DW_AT_const_value attribute, whose value represent the actual return value of the concrete inline instance. Such entry also have DW_AT_call_file, DW_AT_call_line and DW_AT_call_col, indicating where the subroutine is called.

4.1: Data Object Entries

An entry describing a variable may have a DW_AT_const_expr attribute, whose value is a flag which indicate that the variable can be evaluated as a compile-time constant.

In C++, a variable declared with constexpr is implicitly const. Such variable has a DW_AT_type attribute, whose value is a reference to a debugging information entry describing a const qualified type.