3046. Do not require reference_wrapper to support non-referenceable function types

Section: 23.14.5 [refwrap] Status: New Submitter: Jonathan Wakely Opened: 2017-12-14 Last modified: 2017-12-16

Priority: Not Prioritized

View all other issues in [refwrap].

View all issues with New status.

Discussion:

[refwrap] says that reference_wrapper<T> is a "wrapper around a reference to an object or function of type T" but this doesn't actually constrain it, and doesn't forbid non-referenceable function types like int() const.

There is no way to construct a reference_wrapper<int() const> but implementations are required to provide partial specializations for functions with cv-qualifiers and ref-qualifiers in order to define a nested result_type. It should be undefined to instantiate reference_wrapper<T> with a non-referenceable type, or with a reference type (since references to references are not possible). Making it undefined (rather than ill-formed or unspecified) means implementations are not required to diagnose such invalid specializations, but also don't have to go to the effort of supporting weak result types etc.

Proposed resolution:

This wording is relative to N4713.

  1. Modify 23.14.5 [refwrap] as indicated:

    -1- reference_wrapper<T> is a CopyConstructible and CopyAssignable wrapper around a reference to an object or function of type T. T shall be a referenceable type (20.3.18 [defns.referenceable]) that is not a reference type.

    -2- reference_wrapper<T> shall be a trivially copyable type (6.7 [basic.types]).