]> granicus.if.org Git - icu/commitdiff
ICU-8298 avoid ambiguous method matching for MaybeStackArray[index]
authorMarkus Scherer <markus.icu@gmail.com>
Mon, 4 Jun 2012 23:51:39 +0000 (23:51 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Mon, 4 Jun 2012 23:51:39 +0000 (23:51 +0000)
X-SVN-Rev: 31903

icu4c/source/common/cmemory.h
icu4c/source/i18n/digitlst.cpp
icu4c/source/test/intltest/dcfmtest.cpp

index 8feb7009c213be28fc2a7ca53fbf4d93bc987082..78db8c529ceb86d6d14255206eddb5d794e910c5 100644 (file)
@@ -251,12 +251,15 @@ public:
      * @return getAlias()+getCapacity()
      */
     T *getArrayLimit() const { return getAlias()+capacity; }
+    // No "operator T *() const" because that can make
+    // expressions like mbs[index] ambiguous for some compilers.
     /**
-     * Access without ownership change. Same as getAlias().
-     * A class instance can be used directly in expressions that take a T *.
-     * @return the array pointer
+     * Array item access (const).
+     * No index bounds check.
+     * @param i array index
+     * @return reference to the array item
      */
-    operator T *() const { return ptr; }
+    const T &operator[](ptrdiff_t i) const { return ptr[i]; }
     /**
      * Array item access (writable).
      * No index bounds check.
index 9aaf0491756f3e9f53d33cc2a8c3c399365faf7d..ec3dc971962ced94a340f7d5f90e8b601a473691 100644 (file)
@@ -462,21 +462,21 @@ DigitList::getDouble() const
             DigitList numToConvert(*this);
             numToConvert.reduce();    // Removes any trailing zeros, so that digit count is good.
             numToConvert.round(MAX_DBL_DIGITS+3);
-            uprv_decNumberToString(numToConvert.fDecNumber, s);
+            uprv_decNumberToString(numToConvert.fDecNumber, s.getAlias());
             // TODO:  how many extra digits should be included for an accurate conversion?
         } else {
-            uprv_decNumberToString(this->fDecNumber, s);
+            uprv_decNumberToString(this->fDecNumber, s.getAlias());
         }
         U_ASSERT(uprv_strlen(&s[0]) < MAX_DBL_DIGITS+18);
         
         if (decimalSeparator != '.') {
-            char *decimalPt = strchr(s, '.');
+            char *decimalPt = strchr(s.getAlias(), '.');
             if (decimalPt != NULL) {
                 *decimalPt = decimalSeparator;
             }
         }
         char *end = NULL;
-        tDouble = uprv_strtod(s, &end);
+        tDouble = uprv_strtod(s.getAlias(), &end);
     }
     {
         Mutex mutex;
index 39bb5ac5e75fa72d763bc07a5f0df12cdaf1caf4..6a55e7a010079d0f8e836c95022594b41672a534 100644 (file)
@@ -1,6 +1,6 @@
 /********************************************************************
  * COPYRIGHT:
- * Copyright (c) 2002-2011, International Business Machines Corporation and
+ * Copyright (c) 2002-2012, International Business Machines Corporation and
  * others. All Rights Reserved.
  ********************************************************************/
 
@@ -112,7 +112,7 @@ InvariantStringPiece::InvariantStringPiece(const UnicodeString &s) {
     }
     // Buffer size is len+1 so that s.extract() will nul-terminate the string.
     s.extract(0, len, buf.getAlias(), len+1, US_INV);
-    this->set(buf, len);
+    this->set(buf.getAlias(), len);
 }
 
 
@@ -138,7 +138,7 @@ UnicodeStringPiece::UnicodeStringPiece(const UnicodeString &s) {
         capacity = requiredCapacity;
         s.extract(0, len, buf.getAlias(), capacity);
     }
-    this->set(buf, requiredCapacity - 1);
+    this->set(buf.getAlias(), requiredCapacity - 1);
 }