Skip to content

[conv.qual] Adding const with pointers to arrays in the qualification-combined type #987

Description

@Halalaluyafail3

Full name of submitter (unless configured in github; will be published with the issue): Jay Ghiron

Reference (section label): [conv.qual]/3.3

Issue description:

Consider the type of 0?(int(*)[])0:(volatile int(*)[])0, the longest qualification-decomposition (n=2) for the types of both the second and the third operands should be:

  • int(*)[]: cvi1 is empty for any i, P01 is "pointer to", P11 is "array of unknown bound of", and U1 is the type int.
  • volatile int(*)[]: cv02 is empty, cv12 and cv22 are both volatile, P02 is "pointer to", P12 is "array of unknown bound of", and U2 is the type int.

Following the rules of qualification-combined types:

  • P03 is "pointer to", P13 is "array of unknown bound of", and U3 is the type int.
  • cv03 is unspecified, cv13 is const volatile, and cv23 is volatile.

However, such a type cannot exist because it requires an array type that is const while its element type is not const. I believe the intent here is that const should not be added, otherwise it would be inconsistent with C. See also CWG2438.

Suggested resolution:

Modify [conv.qual]/3:

The qualification-combined type of two types T1 and T2 is the type T3 similar to T1 whose qualification-decomposition with the greatest value of n is such that:

  • cv03 is empty,
  • for every i>0, cvi3 is the union of cvi1 and cvi2,
  • if either Pi1 or Pi2 is "array of unknown bound of", Pi3 is "array of unknown bound of", otherwise it is Pi1, and
  • if the resulting cvi3 is different from cvi1 or cvi2, or the resulting Pi3 is different from Pi1 or Pi2, then const is added to every cvk3 for 0<k<i≤l where l is the largest value such that 0≤l<i and Pl3 is neither "array of Nl3" nor "array of unknown bound of",

where cvij and, Pij, and Nij are the components of the qualification-decomposition of T j. A prvalue of type T1 can be converted to type T2 if the qualification-combined type of T1 and T2 is T2.

This resolves points one and three of CWG2438. For point two, if U1 and U2 are different then those types are not similar. For point four, if either Pi1 or Pi2 is "array of unknown bound of" then the other must be "array of unknown bound of" or "array of Niother" for the types to be similar. For point five, if any changes are needed then those should be done in [expr.type]/3 where composite pointer type is defined.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions