Title
Pointer arithmetic with similar types
Status
tentatively ready
Section
7.6.6 [expr.add]
Submitter
Jay Ghiron

Created on 2026-04-26.00:00:00 last changed 1 week ago

Messages

Date: 2026-04-29.21:37:05

Proposed resolution (approved by CWG 2026-04-28):

Change in 7.6.6 [expr.add] paragraph 2 as follows:

For subtraction, one of the following shall hold:
  • both operands have arithmetic type; or
  • both operands are pointers to cv-qualified or cv-unqualified versions of the same similar (7.3.6 [conv.qual]) completely-defined object type types; or
  • the left operand is a pointer to a completely-defined object type and the right operand has integral type.
Date: 2026-04-26.00:00:00

(From submission #892.)

Consider:

char**p;
int diff = p - (const char * const *)p;

This is ill-formed per 7.6.6 [expr.add] paragraph 2, but ought to be allowed, in harmony with 7.6.9 [expr.rel] paragraph 3, 7.6.10 [expr.eq] paragraph 3, and 7.6.16 [expr.cond] paragraph 4.

History
Date User Action Args
2026-04-29 21:37:05adminsetstatus: open -> tentatively ready
2026-04-26 05:51:02adminsetmessages: + msg8556
2026-04-26 00:00:00admincreate