octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rc/ov.h:166: warning: 'octave_value::rep' should be initialized in the m


From: John W. Eaton
Subject: rc/ov.h:166: warning: 'octave_value::rep' should be initialized in the member initialization list
Date: Fri, 14 Jan 2011 14:14:25 -0500

On 14-Jan-2011, CdeMills wrote:

| Could someone please enlighten my weak comprehension of C++ with regard to
| ov.h ?
| 
| Line 166:
| octave_value (void)
|     {
|       static octave_base_value nil_rep;
|       rep = &nil_rep;
|       rep->count++;
|     }

We could avoid the warning by writing it as

  octave_value (void) : rep (0)
    {
      static octave_base_value nil_rep;
      rep = &nil_rep;
      rep->count++;
    }

Note that the octave_base_value constructor sets the count to 1, so by
incrementing it here, we ensure that this object can never be deleted,
so it should be safe to use the static member instead of allocating it
with new.

| Moreover, as count is an octave_idx_type, which is an int, shouldn't case
| where count < 0 be detected and flagged  ? They should not occur, but 
| better sure than sorry.

Maybe we should use assert (rep->count >= 0) here?  If the count is
less than zero, it is a serious bug, so I don't think we should allow
it in any case.  Though I do think there are some other classses that
use the <= 0 test instead and will silently let a bug like this slip.
Maybe they should be fixed too?

BTW, what compiler flags are you using that show these warnings?

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]