From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e8ef51420f80a908 X-Google-Attributes: gidfee84,public From: dsr@mail.lns.cornell.edu (Daniel S. Riley) Subject: Re: Annoying bug/warning in CXX on Digital Date: 1999/07/29 Message-ID: #1/1 X-Deja-AN: 506675373 References: <37A02650.CA828161@cosmosbay.com> Organization: LNS, Cornell U., Ithaca, NY 14853 Newsgroups: comp.unix.osf.osf1 Eric Dumazet 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 "History teaches us that days like this are best spent in bed"