Skip to content

Specify the context type for the index in an increment/decrement operation #2271

@eernstg

Description

@eernstg

The context type for an expression of the form e1[e2]++, e1[e2]--, ++e1[e2], --e1[e2] is apparently not specified.

In the case where the corresponding operator declarations have parameter types T1 and T2 for the index, the most general type that would work is the greatest lower bound of T1 and T2, so we would most likely use the standard lower bound (which is an approximation of the greatest lower bound).

class C {
  T0 operator[](T1 index) ...
  operator[]=(T2 index, T3 value) ...
}

X whatever<X>() {
  print(X);
  throw 0;
}

void main() {
  C()[whatever()]++; // Prints the standard lower bound of `T1` and `T2`.
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions