Annoying warning

bridged with qdn.public.qnxrtp.devtools
Bill Caroselli

Annoying warning

Post by Bill Caroselli » Tue Apr 01, 2003 9:00 pm

Using qcc from PhAB on a C++ file I get many of this very annoying
warning:
../callbacks.cc:23: warning: `my_type * ptr' might be used
uninitialized in this function

The lines of code that would produce this look something like this:
my_type * ptr; // this line is flagged with this warning.
ptr = something_that_returns_a_my_type_ptr();

The PhAB command line looks like this:
qcc -Vgcc_ntox86_gpp -w8 -O -O3 -fomit-frame-pointer
-I. -c -o callbacks.o ../callbacks.cc

How can I disable this annoying warning?
(Yes in know I can assign to it when it is declaired, but I don't
want to.)

I do like to keep my warning level set very high. But I don't
consider this a valid warning.

P.S. Other C++ compilers (who shall remain Watcom) can correctly
report "Used before set" warnings.

Chris McKillop

Re: Annoying warning

Post by Chris McKillop » Tue Apr 01, 2003 10:15 pm

Can you post the full function Bill? I tried a little demo app based on
what you described and I cannot get the warning to come out.

warn.c:
typedef struct
{
int foo;
int bar;
} my_type;

my_type* something_that_returns_a_my_type_ptr() {
return new my_type;
}

int main( int argc, char **argv )
{
my_type *ptr;
ptr = something_that_returns_a_my_type_ptr();
delete ptr;
return 0;
}

qcc -Vgcc_ntox86_gpp -w8 -O -O3 -fomit-frame-pointer -c -o warn.o warn.cc

Compiles without warning.

chris



Bill Caroselli <qtps@earthlink.net> wrote:
Using qcc from PhAB on a C++ file I get many of this very annoying
warning:
../callbacks.cc:23: warning: `my_type * ptr' might be used
uninitialized in this function

The lines of code that would produce this look something like this:
my_type * ptr; // this line is flagged with this warning.
ptr = something_that_returns_a_my_type_ptr();

The PhAB command line looks like this:
qcc -Vgcc_ntox86_gpp -w8 -O -O3 -fomit-frame-pointer
-I. -c -o callbacks.o ../callbacks.cc

How can I disable this annoying warning?
(Yes in know I can assign to it when it is declaired, but I don't
want to.)

I do like to keep my warning level set very high. But I don't
consider this a valid warning.

P.S. Other C++ compilers (who shall remain Watcom) can correctly
report "Used before set" warnings.
--
Chris McKillop <cdm@qnx.com> "The faster I go, the behinder I get."
Software Engineer, QSSL -- Lewis Carroll --
http://qnx.wox.org/

Bill Caroselli

Re: Annoying warning

Post by Bill Caroselli » Tue Apr 01, 2003 10:36 pm

Chris McKillop <cdm@qnx.com> wrote:
Can you post the full function Bill? I tried a little demo app based on
what you described and I cannot get the warning to come out.
NO!

Well actually (blush), I had a nice example all ready to post here.
I started trimming the unrelated stuff to post the shortest example
possible. When I did the problem went away.

So I slowly started replacing lines and saw what it was really bitching
about. It was my fault. But the warning message was pointing me in
the wrong direction.

I just need to become more intimate with GNU I guess. After over a
decade I start to actually think like the Watcom compiler thinks.
When it says something I tend to know exactly what it means. I
haven't achieved that level of intimacey with GNU yet.

Chris McKillop

Re: Annoying warning

Post by Chris McKillop » Tue Apr 01, 2003 11:11 pm

Well actually (blush), I had a nice example all ready to post here.
I started trimming the unrelated stuff to post the shortest example
possible. When I did the problem went away.

So I slowly started replacing lines and saw what it was really bitching
about. It was my fault. But the warning message was pointing me in
the wrong direction.

I just need to become more intimate with GNU I guess. After over a
decade I start to actually think like the Watcom compiler thinks.
When it says something I tend to know exactly what it means. I
haven't achieved that level of intimacey with GNU yet.
You have seen a picture of a GNU right? You might not want to get too close. :)

Glad to hear you found your troubles.

chris

--
Chris McKillop <cdm@qnx.com> "The faster I go, the behinder I get."
Software Engineer, QSSL -- Lewis Carroll --
http://qnx.wox.org/

Kris Warkentin

Re: Annoying warning

Post by Kris Warkentin » Wed Apr 02, 2003 1:39 pm

I find it annoying to get that warning as well. I often see it in a case
like:

if( (fd = open("blah",O_RDONLY)) != -1){
....

and get a warning about fd being uninitialized. It seems kind of dumb since
there's no way for it to make it through that statement uninitialized.

cheers,

Kris

"Bill Caroselli" <qtps@earthlink.net> wrote in message
news:b6d48m$qhn$1@inn.qnx.com...
Chris McKillop <cdm@qnx.com> wrote:

Can you post the full function Bill? I tried a little demo app based on
what you described and I cannot get the warning to come out.

NO!

Well actually (blush), I had a nice example all ready to post here.
I started trimming the unrelated stuff to post the shortest example
possible. When I did the problem went away.

So I slowly started replacing lines and saw what it was really bitching
about. It was my fault. But the warning message was pointing me in
the wrong direction.

I just need to become more intimate with GNU I guess. After over a
decade I start to actually think like the Watcom compiler thinks.
When it says something I tend to know exactly what it means. I
haven't achieved that level of intimacey with GNU yet.

Colin Burgess

Re: Annoying warning

Post by Colin Burgess » Wed Apr 02, 2003 2:21 pm

-Wno-uninitialized will suppress this message

/usr/lib/gcc-lib/nto<cpu>/2.95.3/cc1 --help for a list of warnings. They
can all be turned off by addign no-

Bill Caroselli <qtps@earthlink.net> wrote:
Using qcc from PhAB on a C++ file I get many of this very annoying
warning:
../callbacks.cc:23: warning: `my_type * ptr' might be used
uninitialized in this function

The lines of code that would produce this look something like this:
my_type * ptr; // this line is flagged with this warning.
ptr = something_that_returns_a_my_type_ptr();

The PhAB command line looks like this:
qcc -Vgcc_ntox86_gpp -w8 -O -O3 -fomit-frame-pointer
-I. -c -o callbacks.o ../callbacks.cc

How can I disable this annoying warning?
(Yes in know I can assign to it when it is declaired, but I don't
want to.)

I do like to keep my warning level set very high. But I don't
consider this a valid warning.

P.S. Other C++ compilers (who shall remain Watcom) can correctly
report "Used before set" warnings.
--
cburgess@qnx.com

Bill Caroselli

Re: Annoying warning

Post by Bill Caroselli » Wed Apr 02, 2003 6:32 pm

Colin Burgess <cburgess@qnx.com> wrote:
-Wno-uninitialized will suppress this message

/usr/lib/gcc-lib/nto<cpu>/2.95.3/cc1 --help for a list of warnings. They
can all be turned off by addign no-
Thank you. This is helpful.

The warning is also helpful when it is correctly issued. And like I
said, I do like to keep my warning level set very high. I have
worked at places where it was company policy that no code be accepted
unless it compiled cleanly with a maximum warning level set.

Rennie Allen

Re: Annoying warning

Post by Rennie Allen » Fri Apr 04, 2003 2:39 pm

Chris McKillop wrote:
You have seen a picture of a GNU right? You might not want to get too close. :)
Not to mention that the consequences of rejection can be severe ;-)

Rennie

Bill Caroselli

Re: Annoying warning

Post by Bill Caroselli » Wed Apr 30, 2003 10:43 pm

I have a new annoying warning.

I have a debug class that is only usful for it's constructor and
destructor. A stripped down version looks like this:

class Tracer
{
const char * name;
public:
Tracer ( const char * fn ) : name( fn )
{ cerr << "Entered Function " << name << endl; }
~Tracer ( )
{ cerr << "Exited Function " << name << endl; }
};

Then in a function I can have:

void do_something ()
{
Tracer fn( "do_something()" );
}

and it will display every time that function is entered and exited.

But with GNU the compiler complains:
test_tracer.cc: In function `void do_something()':
test_tracer.cc:<line number>: warning: unused variable `struct Tracer fn'

It was in fact used because of it's construstoc & destructor.
What can I use to get rid of this warning?

Bill Caroselli

Re: Annoying warning

Post by Bill Caroselli » Wed Apr 30, 2003 10:45 pm

Got it!

The compiler seems to like having no object name. I.E.

void do_something ()
{
Tracer ( "do_something()" );
}

Weird, but it works.


Bill Caroselli <qtps@earthlink.net> wrote:
BC > I have a new annoying warning.

BC > I have a debug class that is only usful for it's constructor and
BC > destructor. A stripped down version looks like this:

BC > class Tracer
BC > {
BC > const char * name;
BC > public:
BC > Tracer ( const char * fn ) : name( fn )
BC > { cerr << "Entered Function " << name << endl; }
BC > ~Tracer ( )
BC > { cerr << "Exited Function " << name << endl; }
BC > };

BC > Then in a function I can have:

BC > void do_something ()
BC > {
BC > Tracer fn( "do_something()" );
BC > }

BC > and it will display every time that function is entered and exited.

BC > But with GNU the compiler complains:
BC > test_tracer.cc: In function `void do_something()':
BC > test_tracer.cc:<line number>: warning: unused variable `struct Tracer fn'

BC > It was in fact used because of it's construstoc & destructor.
BC > What can I use to get rid of this warning?

Bill Caroselli

Re: Annoying warning

Post by Bill Caroselli » Wed Apr 30, 2003 11:21 pm

Nope. No cigar.

Not including an object name gets rid of the warning.
It also gets rid of the object.

Does anyone else know a work around for this?

A class is only useful for it's constructor and destructor.
It is otherwise not referenced. But te compiler complains
about it not being referenced.

How can I get rid of this warning?


Bill Caroselli <qtps@earthlink.net> wrote:
BC > Got it!

BC > The compiler seems to like having no object name. I.E.

BC > void do_something ()
BC > {
BC > Tracer ( "do_something()" );
BC > }

BC > Weird, but it works.


BC > Bill Caroselli <qtps@earthlink.net> wrote:
BC > BC > I have a new annoying warning.

BC > BC > I have a debug class that is only usful for it's constructor and
BC > BC > destructor. A stripped down version looks like this:

BC > BC > class Tracer
BC > BC > {
BC > BC > const char * name;
BC > BC > public:
BC > BC > Tracer ( const char * fn ) : name( fn )
BC > BC > { cerr << "Entered Function " << name << endl; }
BC > BC > ~Tracer ( )
BC > BC > { cerr << "Exited Function " << name << endl; }
BC > BC > };

BC > BC > Then in a function I can have:

BC > BC > void do_something ()
BC > BC > {
BC > BC > Tracer fn( "do_something()" );
BC > BC > }

BC > BC > and it will display every time that function is entered and exited.

BC > BC > But with GNU the compiler complains:
BC > BC > test_tracer.cc: In function `void do_something()':
BC > BC > test_tracer.cc:<line number>: warning: unused variable `struct Tracer fn'

BC > BC > It was in fact used because of it's construstoc & destructor.
BC > BC > What can I use to get rid of this warning?


P.S. Anyone else is free to jion in on my conversation.

Mario Charest

Re: Annoying warning

Post by Mario Charest » Thu May 01, 2003 12:55 am

"Bill Caroselli" <qtps@earthlink.net> wrote in message
news:b8pji2$40o$1@inn.qnx.com...
I have a new annoying warning.

I have a debug class that is only usful for it's constructor and
destructor. A stripped down version looks like this:

class Tracer
{
const char * name;
public:
Tracer ( const char * fn ) : name( fn )
{ cerr << "Entered Function " << name << endl; }
~Tracer ( )
{ cerr << "Exited Function " << name << endl; }
};

Then in a function I can have:

void do_something ()
{
Tracer fn( "do_something()" );
}

and it will display every time that function is entered and exited.
Sorry can't help you with the warning, but I wonder if the behavior you
expect is really standard. My understanding of scope says that whenever the
object isn't use the compiler is free to decide when the desctructor is
called.

thus:

void do_something ()
{
Tracer fn( "do_something()" );
printf("a\n");
}

I *beleive* the compiler is free to called the desctructor before the
printf. In general I don't beleive that is the case, since all compiler I
know will free object allocated on the stack when the fonction returns (in
you example) but I wonder if that behavior is defined by the language.

David Bacon

Re: Annoying warning

Post by David Bacon » Thu May 01, 2003 12:25 pm

Try -Wno-unused

dB

"Mario Charest" <postmaster@127.0.0.1> wrote in message
news:b8pq5n$aru$1@inn.qnx.com...
"Bill Caroselli" <qtps@earthlink.net> wrote in message
news:b8pji2$40o$1@inn.qnx.com...
I have a new annoying warning.

I have a debug class that is only usful for it's constructor and
destructor. A stripped down version looks like this:

class Tracer
{
const char * name;
public:
Tracer ( const char * fn ) : name( fn )
{ cerr << "Entered Function " << name << endl; }
~Tracer ( )
{ cerr << "Exited Function " << name << endl; }
};

Then in a function I can have:

void do_something ()
{
Tracer fn( "do_something()" );
}

and it will display every time that function is entered and exited.

Sorry can't help you with the warning, but I wonder if the behavior you
expect is really standard. My understanding of scope says that whenever
the
object isn't use the compiler is free to decide when the desctructor is
called.

thus:

void do_something ()
{
Tracer fn( "do_something()" );
printf("a\n");
}

I *beleive* the compiler is free to called the desctructor before the
printf. In general I don't beleive that is the case, since all compiler I
know will free object allocated on the stack when the fonction returns (in
you example) but I wonder if that behavior is defined by the language.

Colin Burgess

Re: Annoying warning

Post by Colin Burgess » Thu May 01, 2003 1:15 pm

For some reason I can't reproduce this (what compiler options etc?)

But you can add a __attribute__((__unused__)) to the definition
of Tracer

From the gcc html manual

unused

When attached to a type (including a union or a struct),
this attribute means that variables of that type are meant to appear
possibly unused. GNU CC will not produce a warning for any variables of
that type, even if the variable appears to do nothing. This is often
the case with lock or thread classes, which are usually defined and then
not referenced, but contain constructors and destructors that have
nontrivial bookkeeping functions.

Bill Caroselli <qtps@earthlink.net> wrote:
I have a new annoying warning.

I have a debug class that is only usful for it's constructor and
destructor. A stripped down version looks like this:

class Tracer
{
const char * name;
public:
Tracer ( const char * fn ) : name( fn )
{ cerr << "Entered Function " << name << endl; }
~Tracer ( )
{ cerr << "Exited Function " << name << endl; }
};

Then in a function I can have:

void do_something ()
{
Tracer fn( "do_something()" );
}

and it will display every time that function is entered and exited.

But with GNU the compiler complains:
test_tracer.cc: In function `void do_something()':
test_tracer.cc:<line number>: warning: unused variable `struct Tracer fn'

It was in fact used because of it's construstoc & destructor.
What can I use to get rid of this warning?
--
cburgess@qnx.com

David Bacon

Re: Annoying warning

Post by David Bacon » Thu May 01, 2003 2:03 pm

That looks like the nicest solution, Colin. FYI, I didn't actually use
Bill's original example, I just applied qcc (lowercase) to

main() {
int a;
return 0;
}

with -Wall -Wno-unused. The same works for gcc.

dB

"Colin Burgess" <cburgess@qnx.com> wrote in message
news:b8r6l8$627$1@nntp.qnx.com...
For some reason I can't reproduce this (what compiler options etc?)

But you can add a __attribute__((__unused__)) to the definition
of Tracer

From the gcc html manual

unused

When attached to a type (including a union or a struct),
this attribute means that variables of that type are meant to appear
possibly unused. GNU CC will not produce a warning for any variables of
that type, even if the variable appears to do nothing. This is often
the case with lock or thread classes, which are usually defined and then
not referenced, but contain constructors and destructors that have
nontrivial bookkeeping functions.

Bill Caroselli <qtps@earthlink.net> wrote:
I have a new annoying warning.

I have a debug class that is only usful for it's constructor and
destructor. A stripped down version looks like this:

class Tracer
{
const char * name;
public:
Tracer ( const char * fn ) : name( fn )
{ cerr << "Entered Function " << name << endl; }
~Tracer ( )
{ cerr << "Exited Function " << name << endl; }
};

Then in a function I can have:

void do_something ()
{
Tracer fn( "do_something()" );
}

and it will display every time that function is entered and exited.

But with GNU the compiler complains:
test_tracer.cc: In function `void do_something()':
test_tracer.cc:<line number>: warning: unused variable `struct Tracer
fn'

It was in fact used because of it's construstoc & destructor.
What can I use to get rid of this warning?


--
cburgess@qnx.com

Post Reply

Return to “qdn.public.qnxrtp.devtools”