From: dsr@mail.lns.cornell.edu (Daniel S. Riley)
Subject: Re: Annoying bug/warning in CXX on Digital
Date: 1999/07/29 [thread overview]
Message-ID: <shso67722i.fsf@lnscu4.lns.cornell.edu> (raw)
In-Reply-To: 37A02650.CA828161@cosmosbay.com
Eric Dumazet <Eric.Dumazet@cosmosbay.com> writes:
> # cat bug.C
> typedef void * Opaque ;
>
> const Opaque func(void)
> {
> return 0 ;
> }
> # cxx -c -w0 bug.C
> cxx: Info: bug.C, line 3: type qualifier on return type is meaningless
> const Opaque func(void)
> -------------^
As I understand this, the type of "const Opaque" is "void* const"
(const pointer to void), not "const void*" (pointer to const void).
Since "pointer to void" as a return value isn't modifiable, declaring
it const is a no-op--the "const" does nothing, similar to "const int
func()". If the type were "const void*", you wouldn't get the
warning, as the "void" pointed to by the "const void*" is potentially
modifiable, and hence declaring it const means something.
If that reads like nonsense (and it probably will the first few times),
you need to meditate on the difference between "const pointer to void"
and "pointer to const void". Also try guessing which of these produces
cxx warnings or errors:
typedef void* Opaque;
const Opaque f1() { return 0; }
const void* f2() { return 0; }
void* const f3() { return 0; }
const Opaque& f4() { static Opaque i = 0; return i; }
main()
{
Opaque p1 = f1();
Opaque p2 = f2();
Opaque p3 = f3();
Opaque& p4 = f4();
}
> Is there a workaround (to keep the -w0 option but supress this kind of
> warning)
First, consider whether cxx might be right. The "const" isn't doing
anything--if you thought it was, then you probably want
typedef const void * Opaque ;
Opaque func(void)
{
return 0 ;
}
instead. If you really just want to suppress the warning, here's the
recipe:
dsr_lnscu4% cxx -c -w0 -msg_display_tag warn.cc
cxx: Warning: warn.cc, line 3: type qualifier on return type is meaningless (D:useless_type_qualifier_on_return_type)
const Opaque func(void)
-------------^
dsr_lnscu4% cxx -c -w0 -msg_disable useless_type_qualifier_on_return_type warn.cc
dsr_lnscu4%
or
dsr_lnscu4% cxx -c -w0 -msg_display_number warn.cc
cxx: Warning: warn.cc, line 3: #824-D type qualifier on return type is meaningless
const Opaque func(void)
-------------^
dsr_lnscu4% cxx -c -w0 -msg_disable 824 warn.cc
dsr_lnscu4%
--
Dan Riley dsr@mail.lns.cornell.edu
Wilson Lab, Cornell University <URL:http://www.lns.cornell.edu/~dsr/>
"History teaches us that days like this are best spent in bed"
next prev parent reply other threads:[~1999-07-29 4:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-07-29 4:00 Annoying bug/warning in CXX on Digital Eric Dumazet
1999-07-29 4:00 ` Daniel S. Riley [this message]
1999-07-30 4:00 ` Eric Dumazet
1999-07-30 4:00 ` Daniel S. Riley
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox