Kay Ramme - Sun Germany - Hamburg wrote:
Hi,

please correct me, if I am wrong. I understand this as a 'C' inherited C++ oddity (no constructors for integral values), which leads to a warning if the first operation on the integral value is not classified as "assignment". Obviously 'operator >>=' has not been classified as "assignment" at least not for the right operand.

No, the compiler does not assume the user-supplied operator >>= has any assignment semantics. Rather, as the operator >>= is inline, GCC tries an analysis whether or not b is definitely assigned at point (1) in

  com::sun::star::uno::Any a;
  T b;
  if (a >>= b) {
    // (1)
  }

Depending on T (i.e., depending on the complexity of the relevant inline operator >>=):

- GCC sometimes comes up with the insight that b is definitely assigned at (1), which is correct, and in which case GCC does not issue a warning (why should it?);

- GCC sometimes cannot decide whether or not b is definitely assigned at (1), although it *is*, and in which case GCC conservatively does not issue a warning;

- GCC sometimes comes up with the insight that b is not definitely assigned at (1), which is an incorrect analysis, and in which case GCC erroneously issues a warning.

So, it seems that we have used the wrong operator here. Therefor I tend to agree to Frank, that we may want to fix this.

The choice of operator is indeed unfortunate.  However, I do not agree that

  - T b;
  + T b = T();

is in general a fix that improves code quality.

-Stephan

Kay

Frank Schönheit - Sun Microsystems Germany wrote:
Nonetheless, I would not consider initializing b with something
meaningful a mutilation. And be it just because months later, somebody
will be tempted to re-use b some lines below.

Ciao
Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to