Movatterモバイル変換


[0]ホーム

URL:


Issue 1687 - WG21 CWG Issues
Title
Conversions of operands of built-in operators
Status
c++14
Section
12.2.2.3 [over.match.oper]
Submitter
Richard Smith

Created on2013-05-17.00:00:00 last changed136 months ago

Messages

msg4962 (view)
Date: 2014-02-15.00:00:00

[Moved to DR at the February, 2014 meeting.]

msg4737 (view)
Date: 2014-01-15.00:00:00

Proposed resolution (January, 2014):

Change 12.2.2.3 [over.match.oper] paragraph 7 as follows:

If a built-in candidate is selected by overload resolution,the operandsof class type are converted to thetypes of the corresponding parameters of the selectedoperation function, except that the second standardconversion sequence of a user-defined conversion sequence(12.2.4.2.3 [over.ics.user]) is notapplied. Then the operator is treated as thecorresponding built-in operator and interpreted according toClause 7 [expr].[Example:

  struct X {    operator double();  };  struct Y {    operator int*();  };  int *a = Y() + 100.0; // error: pointer arithmetic requires integral operand  int *b = Y() + X();   // error: pointer arithmetic requires integral operand

end example]

msg4538 (view)
Date: 2022-02-18.07:47:23

Consider an example like:

  struct Y {    operator int*();  };  extern int *p;  int *a = p + 100.0;   // #1  int *b = Y() + 100.0; // #2

#1 is ill-formed because it violates the requirement of7.6.6 [expr.add] that the non-pointer operand have integralor enumeration type. It appears that #2 is well-formed, however,because 12.2.2.3 [over.match.oper] paragraph 7 says,

If a built-in candidate is selected by overload resolution, the operandsare converted to the types of the corresponding parameters of the selectedoperation function. Then the operator is treated as the correspondingbuilt-in operator and interpreted according toClause 7 [expr].

In this case, the selected operation function is

  int *operator+(int *, std::ptrdiff_t)

100.0 is thus converted tostd::ptrdiff_t beforereaching 7.6.6 [expr.add].

This problem could be addressed by restricting the conversion tothe class or enumeration operand rather than both operands.

History
DateUserActionArgs
2014-11-24 00:00:00adminsetstatus: dr -> c++14
2014-03-03 00:00:00adminsetmessages: +msg4962
2014-03-03 00:00:00adminsetstatus: tentatively ready -> dr
2014-01-20 00:00:00adminsetmessages: +msg4737
2014-01-20 00:00:00adminsetstatus: drafting -> tentatively ready
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-05-17 00:00:00admincreate

[8]ページ先頭

©2009-2026 Movatter.jp