This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


573. Conversions between function pointers and void*

Section: 7.6.1.10  [expr.reinterpret.cast]     Status: C++11     Submitter: Steve Adamczyk     Date: 13 April 2006

[Voted into the WP at the March, 2011 meeting.]

The resolution to issue 195 makes “converting a pointer to a function into a pointer to an object type or vice versa” conditionally-supported behavior. In doing so, however, it overlooked the fact that void is not an “object type” (6.8 [basic.types] paragraph 9). The wording should be amended to allow conversion to and from void* types.

Proposed resolution (November, 2010):

  1. Change _N4885_6.7.5.5.4 [basic.stc.dynamic.safety] paragraphs 1-2 as follows:

  2. A traceable pointer object is

    A pointer value is a safely-derived pointer to a dynamic object only if it has pointer-to-object an object pointer type and it is...

  3. Change 6.8.4 [basic.compound] paragraphs 3-4 as follows:

  4. The type of a pointer to void or a pointer to an object type is called an object pointer type. [Note: A pointer to void does not have a pointer-to-object type, however, because void is not an object type. —end note] The type of a pointer that can designate a function is called a function pointer type. A pointer to objects of type T is referred to as a “pointer to T.” [Example:...

    Objects of cv-qualified (6.8.5 [basic.type.qualifier]) or cv-unqualified type void* (pointer to void), A pointer to cv-qualified (6.8.5 [basic.type.qualifier]) or cv-unqualified void can be used to point to objects of unknown type. A void* Such a pointer shall be able to hold any object pointer. A cv-qualified or cv-unqualified (6.8.5 [basic.type.qualifier]) An object of type cv void* shall have the same representation and alignment requirements as a cv-qualified or cv-unqualified cv char*.

  5. Change 7.3.12 [conv.ptr] paragraph 1 as follows:

  6. ...A null pointer constant can be converted to a pointer type; the result is the null pointer value of that type and is distinguishable from every other value of pointer to object or pointer to function object pointer or function pointer type...
  7. Change 7.3.13 [conv.mem] paragraph 2 footnote 58 as follows:

  8. ...Note that a pointer to member is not a pointer to object or a pointer to function an object pointer or a function pointer and...
  9. Change 7.6.1.10 [expr.reinterpret.cast] paragraphs 6-8 as follows:

  10. A pointer to a function pointer can be explicitly converted to a pointer to a function pointer of a different type...

    A pointer to an An object pointer can be explicitly converted to a pointer to a different object type an object pointer of a different type...

    Converting a pointer to a function into a pointer to an object function pointer to an object pointer type or vice versa is conditionally-supported...

  11. Change the note in 9.3.4.6 [dcl.fct] paragraph 6 as follows:

  12. [Note: function types are checked during the assignments and initializations of pointer-to-functions, reference-to-functions, and pointer-to-member-functions pointers to functions, references to functions, and pointers to member functions. —end note]
  13. In the “Index of Implementation-defined Behavior,” change the following item as indicated:

  14. converting pointer to function into pointer to object function pointer to object pointer and vice versa

[Drafting note: 7.6.2.9 [expr.delete] paragraph 1 was not changed, so the operand of delete still cannot be a void*. 12.5 [over.built] paragraph 14 was not changed, so void* pointers still do not get overloads for operator-. 13.2 [temp.param] paragraph 4 was not changed and thus continues to allow only pointers to objects, not object pointers, as non-type template parameters.]

(See also issue 1120.)