Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Need `set before used' warning Keywords: c++, warning Message-ID: <462@taumet.com> Date: 27 Sep 90 16:12:49 GMT References: <2@mtnmath.UUCP> Organization: Taumetric Corporation, San Diego Lines: 38 paul@mtnmath.UUCP (paul) writes: >class Example { > char * Point ; >public: > Example(char * point) {point=Point;} >}; >There are two errors that it would be helpful to flag with >warning messages. > 1. Member variable `Point' is used before it is set. > 2. Constructor parameter `point' which is not a reference > is set before it is used. >The latter message could apply to any subroutine definition, while >the former is only valid for constructors. >Is there some reason warnings of this sort should not be given? No reason at all. Some compilers do warn about these kinds of errors. Oregon C++ (not an AT&T port) typically warns about variables used before being set, but does not in this particular instance. Turbo C++ (not an AT&T port) warns about parameter "point" not being used, which is a more correct statement than your #2 above. Both compilers were derived from earlier compilers which did some flow analysis to detect local variables used before being set. The case of a data member used before being set in a constructor requires a different sort of test, and was evidently overlooked in these two compilers. Non-dyslexics can also make the sort of error you have here, and it is worth checking for, as a "quality of implementation" compiler issue. However, this example is also an argument for choosing distinct names, rather than "Point" and "point" which are easily confused. -- Steve Clamage, TauMetric Corp, steve@taumet.com