Title
Old-style casts with conversion functions
Status
nad
Section
7.6.3 [expr.cast]
Submitter
Daniel Krügler

Created on 2009-06-02.00:00:00 last changed 186 months ago

Messages

Date: 2009-07-15.00:00:00

Rationale (July, 2009):

According to the straightforward interpretation of the wording, the example should work. This appears to be just a compiler bug.

Date: 2022-11-20.07:54:16

According to 7.6.3 [expr.cast] paragraph 4, one possible interpretation of an old-style cast is as a static_cast followed by a const_cast. One would therefore expect that the expressions marked #1 and #2 in the following example would have the same validity and meaning:

    struct S {
      operator const int* ();
    };

    void f(S& s)  {
      const_cast<int*>(static_cast<const int*>(s));  // #1
      (int*) s;  // #2
    }

However, a number of implementations issue an error on #2.

Is the intent that (T*)x should be interpreted as something like

    const_cast<T*>(static_cast<const volatile T*>(x))
History
Date User Action Args
2009-08-03 00:00:00adminsetmessages: + msg2274
2009-08-03 00:00:00adminsetstatus: open -> nad
2009-06-02 00:00:00admincreate