This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8176: C++ const**, doesn't implictly cast
- From: charles at kde dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 9 Oct 2002 19:05:02 -0000
- Subject: c++/8176: C++ const**, doesn't implictly cast
- Reply-to: charles at kde dot org
>Number: 8176
>Category: c++
>Synopsis: C++ const**, doesn't implictly cast
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 09 12:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: charles@kde.org
>Release: gcc 2.96 through gcc 3.2, probably 2.95 too
>Organization:
>Environment:
Linux
>Description:
class Bleh { };
void foo(const Bleh **) { }
int main(int, char **)
{
Bleh *bleh;
foo(&bleh); // broken
Bleh **bar;
foo(bar); // broken
foo(const_cast<const Bleh**>(bar)); // works
const Bleh **works;
foo(works); // works
}
This should work, as <Bleh**> can be casted to <const Bleh**> implicitly
Error:
bug.cpp: In function `int main (int, char **)':
bug.cpp:13: `bleh' undeclared (first use this function)
bug.cpp:13: (Each undeclared identifier is reported only once for each function it appears in.)
bug.cpp:16: cannot convert `Bleh **' to `const Bleh **' for argument `1' to `foo (const Bleh **)'
>How-To-Repeat:
Put the compiler in a situation in which it should cast a pointer to a pointer to an object to a pointer to a pointer to a const object (Type** -> const Type**)
>Fix:
Create a more generic code thing to always implicitly cast a something to a const something.
>Release-Note:
>Audit-Trail:
>Unformatted: