|
BUG: No Error When Default Conversion Not PossibleArticle ID: Q148801Creation Date: 22-MAR-1996 Revision Date: 17-JUL-1996
The information in this article applies to:
- The Microsoft C/C++ Compiler (CL.EXE) included with:
Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2
SYMPTOMS A function prototyped to accept a reference to pointer to a const object accepts a reference to a pointer to a non-const object. The conversion is illegal and should be flagged as an error, but it isn't.
STATUS Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION The following is a reference from C++ Standard, Working Papers (8.5.3.4):
Given types "cv1 T1" and "cv2 T2," "cv1 T1" is reference-related to "cv2 T2" if T1 is the same type as T2, or T1 is a base class of T2. "cv1 T1" is reference-compatible with "cv2 T2" if T1 is reference- related to T2 and cv1 is the same cv-qualification as, or greater cv- qualification than, cv2.In terms of the sample code below, rpci1 is of a lesser cv-qualification than rpci because rpci is const and rpci1 is not. Therefore, rpci1 is not reference-compatible with rpci.
Sample Code
/* Compile options needed: /c
*/
void Fun (const int *&rpci); // arg is a reference to a pointer
// to a const int
void FunC (int *&rpci1)
{
Fun(rpci1); // arg is a reference to a pointer to an int
// this line should cause an error
} // conversion is not defined
|
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
©1997 Microsoft Corporation. All rights reserved. Legal Notices.