public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/8176: C++ const**, doesn't implictly cast
@ 2002-10-09 12:46 Andreas Schwab
  0 siblings, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2002-10-09 12:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1158 bytes --]

The following reply was made to PR c++/8176; it has been noted by GNATS.

From: Andreas Schwab <schwab@suse.de>
To: charles@kde.org
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/8176: C++ const**, doesn't implictly cast
Date: Wed, 09 Oct 2002 21:42:03 +0200

 charles@kde.org writes:
 
 |> 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
 
 No, you can't.
 
 class Bleh { int what; };
 const Bleh const_bleh;
 void foo(const Bleh **bleh)
 {
    *bleh = &const_bleh;
 }
 int main()
 {
   Bleh *bleh;
   foo(&bleh);        // assume this is valid
   (*bleh)->what = 1; // modifying const_bleh!
 }
 
 Andreas.
 
 -- 
 Andreas Schwab, SuSE Labs, schwab@suse.de
 SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
 Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
 "And now for something completely different."


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/8176: C++ const**, doesn't implictly cast
@ 2002-10-09 13:31 nathan
  0 siblings, 0 replies; 4+ messages in thread
From: nathan @ 2002-10-09 13:31 UTC (permalink / raw)
  To: charles, gcc-bugs, gcc-prs, nobody

Synopsis: C++ const**, doesn't implictly cast

State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Wed Oct  9 13:31:05 2002
State-Changed-Why:
    not a bug. you are misinterpretting [4.4], which
    allows 'T const *const *' but not 'T const **'

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8176


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/8176: C++ const**, doesn't implictly cast
@ 2002-10-09 13:06 Charles Samuels
  0 siblings, 0 replies; 4+ messages in thread
From: Charles Samuels @ 2002-10-09 13:06 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/8176; it has been noted by GNATS.

From: Charles Samuels <charles@kde.org>
To: Andreas Schwab <schwab@suse.de>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/8176: C++ const**, doesn't implictly cast
Date: Wed, 9 Oct 2002 13:01:09 -0700

 On Wednesday 09 October 2002 12:42 pm, Andreas Schwab wrote:
 > No, you can't.
 >
 > class Bleh { int what; };
 > const Bleh const_bleh;
 > void foo(const Bleh **bleh)
 > {
 >    *bleh =3D &const_bleh;
 > }
 > int main()
 > {
 >   Bleh *bleh;
 >   foo(&bleh);        // assume this is valid
 >   (*bleh)->what =3D 1; // modifying const_bleh!
 > }
 
 Good point, I retract my bug report then.
 
 And then it'd be logical that const Type* const *const, should and so it =
 does.
 
 Thanks
 
 -Charles
 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/8176: C++ const**, doesn't implictly cast
@ 2002-10-09 12:06 charles
  0 siblings, 0 replies; 4+ messages in thread
From: charles @ 2002-10-09 12:06 UTC (permalink / raw)
  To: gcc-gnats


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-10-09 20:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-09 12:46 c++/8176: C++ const**, doesn't implictly cast Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2002-10-09 13:31 nathan
2002-10-09 13:06 Charles Samuels
2002-10-09 12:06 charles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).