[support.srcloc.cons] (original) (raw)
17 Language support library [support]
17.8 Source location [support.srcloc]
17.8.2 Class source_location [support.srcloc.class]
17.8.2.2 Creation [support.srcloc.cons]
static consteval source_location current() noexcept;
Returns:
- When invoked by a function call whose postfix-expression is a (possibly parenthesized) id-expression naming current, returns a source_location with an implementation-defined value.
The value should be affected by #line ([cpp.line]) in the same manner as for __LINE__ and __FILE__.
The values of the exposition-only data members of the returned source_location object are indicated in Table 43.
Table 43 — Value of object returned by current [tab:support.srcloc.current]Line numbers are presumed to be 1-indexed; however, an implementation is encouraged to use 0 when the line number is unknown. An implementation-defined value denoting some offset from the start of the line denoted by line_. Column numbers are presumed to be 1-indexed; however, an implementation is encouraged to use 0 when the column number is unknown. A name of the current function such as in __func__ ([dcl.fct.def.general]) if any, an empty string otherwise. - Otherwise, when invoked in some other way, returns asource_location whose data members are initialized with valid but unspecified values.
Remarks: Any call to current that appears as a default member initializer ([class.mem.general]), or as a subexpression thereof, should correspond to the location of the constructor definition or aggregate initialization that uses the default member initializer.
Any call to current that appears as a default argument ([dcl.fct.default]), or as a subexpression thereof, should correspond to the location of the invocation of the function that uses the default argument ([expr.call]).
[Example 1: struct s { source_location member = source_location::current();int other_member; s(source_location loc = source_location::current()) : member(loc) {} s(int blather) : other_member(blather) {} s(double) {} };void f(source_location a = source_location::current()) { source_location b = source_location::current(); } void g() { f(); source_location c = source_location::current(); f(c); } — _end example_]
constexpr source_location() noexcept;
Effects: The data members are initialized with valid but unspecified values.