Topic: ambiguity in cd2


Author: "Paul D. DeRocco" <pderocco@ix.netcom.crud.com>
Date: 1997/08/31
Raw View
Ron Burk wrote:
>
> Most compilers that I can find believe that it's legal for
> a member function to be declared as (for example)
>    class A { void Foo(char * const x); };
> while the member function is defined without the const:
>   void A::Foo(char* x);
>
> I'm happy to believe that the draft really does intend this to be legal,
> but I do not believe that is what the draft actually currently says. The
> relevant portion of cd2 is this statement (8.3.5 paragraph 3):
>
>  > All declarations for a function with a given parameter list shall agree
> exactly both in the
>  > type of the value returned and in the number and type  of  parameters;

I agree that the standard perhaps shouldn't say "exactly" when it
doesn't really mean exactly. As to why the above situation might arise,
it is because the "const" is really an implementation detail of the
function. I'd be less surprised to see the inverse, where the
declaration leaves off the const, but the definition uses it. In this
case, the caller doesn't care whether the formal parameter is const or
not, but the function itself might want it to be declared const in order
to inform the compiler that the formal parameter will never be modified,
thus suggesting certain optimizations. Not a big deal, though.

--

Ciao,
Paul

(Please remove the extra "crud" from the return address,
which has been altered to foil junk mail senders.)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]