c++/8176: C++ const**, doesn't implictly cast

charles@kde.org charles@kde.org
Wed Oct 9 12:06:00 GMT 2002


>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:



More information about the Gcc-bugs mailing list