Title
Qualification conversion vs reference binding
Status
dup
Section
9.4.4 [dcl.init.ref]
Submitter
Richard Smith

Created on 2014-10-07.00:00:00 last changed 15 months ago

Messages

Date: 2023-09-15.00:00:00

Rationale (September, 2023):

This issue is a duplicate of issue 2352.

Date: 2014-10-07.00:00:00

Qualification conversions are not considered when doing reference binding, which leads to some unexpected results:

  template<typename T> T make();
  struct B {}; struct D : B {};

  const int *p1 = make<int*>();           // ok, qualification conversion
  const int *const *p2 = make<int**>();   // ok, qualification conversion
  const int **p3 = make<int**>();         // error, not type safe

  const int &r1 = make<int&>();           // ok, binds directly
  const int *const &r2 = make<int*&>();   // weird, binds to a temporary
  const int *&r3 = make<int*&>();         // error

  const int &&x1 = make<int&&>();         // ok, binds directly
  const int *const &&x2 = make<int*&&>(); // weird, binds to a temporary
  const int *&&x3 = make<int*&&>();       // weird, binds to a temporary

It might make sense to say that similar types are reference-related and if there is a qualification conversion they are reference-compatible.

See also issue 2023.

History
Date User Action Args
2023-09-16 06:41:53adminsetmessages: + msg7435
2023-09-16 06:41:53adminsetstatus: drafting -> dup
2015-05-25 00:00:00adminsetstatus: open -> drafting
2014-10-07 00:00:00admincreate