Moved the macro from platform.h to uassert.h.
Removed any "unreachable" code that previously occurred after the UPRV_UNREACHABLE macro is used.
Changes based on review from Andy.
Co-authored-by: Daniel Ju <daju@microsoft.com>
return ((c&7)<<18) | ((cpStart[1]&0x3f)<<12) | ((cpStart[2]&0x3f)<<6) | (cpStart[3]&0x3f);
default:
UPRV_UNREACHABLE; // Should not occur.
- return U_SENTINEL;
}
}
}
}
UPRV_UNREACHABLE;
- return -1;
}
void setPosition(int16_t key, int32_t position) {
}
if (i >= kMaxLookaheads) {
UPRV_UNREACHABLE;
- i = kMaxLookaheads - 1;
}
fKeys[i] = key;
fPositions[i] = position;
}
}
UPRV_UNREACHABLE;
- fPositionInCache = -1;
- return FALSE;
}
}
}
UPRV_UNREACHABLE;
- fPositionInCache = -1;
- return FALSE;
}
void RuleBasedBreakIterator::DictionaryCache::populateDictionary(int32_t startPos, int32_t endPos,
while (fBoundaries[fEndBufIdx] < position) {
if (!populateFollowing()) {
UPRV_UNREACHABLE;
- return false;
}
}
fBufIdx = fEndBufIdx; // Set iterator position to the end of the buffer.
*
* File uassert.h
*
-* Contains U_ASSERT macro
-*
-* By default, U_ASSERT just wraps the C library assert macro.
-* By changing the definition here, the assert behavior for ICU can be changed
-* without affecting other non-ICU uses of the C library assert().
+* Contains the U_ASSERT and UPRV_UNREACHABLE macros
*
******************************************************************************
*/
-
#ifndef U_ASSERT_H
#define U_ASSERT_H
+
/* utypes.h is included to get the proper define for uint8_t */
#include "unicode/utypes.h"
+/* for abort */
+#include <stdlib.h>
+
+/**
+ * \def U_ASSERT
+ * By default, U_ASSERT just wraps the C library assert macro.
+ * By changing the definition here, the assert behavior for ICU can be changed
+ * without affecting other non - ICU uses of the C library assert().
+*/
#if U_DEBUG
# include <assert.h>
# define U_ASSERT(exp) assert(exp)
#else
# define U_ASSERT(exp)
#endif
-#endif
+/**
+ * \def UPRV_UNREACHABLE
+ * This macro is used to unconditionally abort if unreachable code is ever executed.
+ * @internal
+*/
+#if defined(UPRV_UNREACHABLE)
+ // Use the predefined value.
+#else
+# define UPRV_UNREACHABLE abort()
+#endif
+#endif
default: /* we should never get here */
UPRV_UNREACHABLE;
- break;
}
}
if((addLevel) || (start < start0)) {
break;
default: /* we should never get here */
UPRV_UNREACHABLE;
- break;
}
}
}
default:
/* we should never get here */
UPRV_UNREACHABLE;
- break;
}
/*
* If there are no external levels specified and there
/* compute the runs array --------------------------------------------------- */
-static int32_t getRunFromLogicalIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode) {
+static int32_t getRunFromLogicalIndex(UBiDi *pBiDi, int32_t logicalIndex) {
Run *runs=pBiDi->runs;
int32_t runCount=pBiDi->runCount, visualStart=0, i, length, logicalStart;
}
/* we should never get here */
UPRV_UNREACHABLE;
- *pErrorCode = U_INVALID_STATE_ERROR;
- return 0;
}
/*
*limit=start+pBiDi->insertPoints.size;
int32_t runIndex;
for(point=start; point<limit; point++) {
- runIndex=getRunFromLogicalIndex(pBiDi, point->pos, pErrorCode);
+ runIndex=getRunFromLogicalIndex(pBiDi, point->pos);
pBiDi->runs[runIndex].insertRemove|=point->flag;
}
}
const UChar *start=pBiDi->text, *limit=start+pBiDi->length, *pu;
for(pu=start; pu<limit; pu++) {
if(IS_BIDI_CONTROL_CHAR(*pu)) {
- runIndex=getRunFromLogicalIndex(pBiDi, (int32_t)(pu-start), pErrorCode);
+ runIndex=getRunFromLogicalIndex(pBiDi, (int32_t)(pu-start));
pBiDi->runs[runIndex].insertRemove--;
}
}
* count is always < length.
*/
UPRV_UNREACHABLE;
- return NULL; /* Never happens if uhash_put() behaves */
}
return &(elements[theIndex]);
}
u=*us++;
if(!UCHAR_IS_INVARIANT(u)) {
UPRV_UNREACHABLE; /* Variant characters were used. These are not portable in ICU. */
- u=0;
}
*cs++=(char)UCHAR_TO_CHAR(u);
--length;
# define U_FALLTHROUGH
#endif
-/**
- * \def UPRV_UNREACHABLE
- * Annotate unreachable code.
- * https://clang.llvm.org/docs/LanguageExtensions.html#builtin-unreachable
- * @internal
-*/
-#if defined(UPRV_UNREACHABLE)
- // Use the predefined value.
-#elif U_DEBUG
- // Assert on Debug builds to catch if "unreachable" code is reached.
-# define UPRV_UNREACHABLE U_ASSERT(FALSE)
-#elif (defined(__GNUC__) && (U_GCC_MAJOR_MINOR >= 405)) || ( defined(__clang__))
-# define UPRV_UNREACHABLE __builtin_unreachable()
-#elif defined(_MSC_VER)
-# define UPRV_UNREACHABLE __assume(0)
-#else
-# define UPRV_UNREACHABLE U_ASSERT(FALSE)
-#endif
-
/** @} */
/*===========================================================================*/
CharacterIterator &WholeStringBreakIterator::getText() const {
UPRV_UNREACHABLE; // really should not be called
- // Returns a null reference.
- // Otherwise we would have to define a dummy CharacterIterator,
- // and either have it as a field and const_cast it to a non-const reference,
- // or have it via a pointer and return a reference to that.
- CharacterIterator *none = nullptr;
- return *none;
}
UText *WholeStringBreakIterator::getUText(UText * /*fillIn*/, UErrorCode &errorCode) const {
if (U_SUCCESS(errorCode)) {
}
void WholeStringBreakIterator::adoptText(CharacterIterator* it) {
UPRV_UNREACHABLE; // should not be called
- length = it->getLength();
- delete it;
}
int32_t WholeStringBreakIterator::first() { return 0; }
break;
default:
UPRV_UNREACHABLE;
- fmt = gExitFmt;
}
va_start(args, returnType);
return 0;
default:
UPRV_UNREACHABLE;
- return 0;
}
int32_t index = findOrInsertNodeForRootCE(ce, strength, errorCode);
break;
default:
UPRV_UNREACHABLE; // require ce32 == base->getFinalCE32(ce32)
- break;
}
return ce32;
}
break;
default:
UPRV_UNREACHABLE; // out of range
- sType = "islamic"; // "islamic" is used as the generic type
- break;
}
return sType;
}
}
} else { // invalid 'civil'
UPRV_UNREACHABLE; // should not get here, out of range
- year=month=0;
}
dayOfMonth = (days - monthStart(year, month)) + 1;
return Field::UNUM_CURRENCY_FIELD;
default:
UPRV_UNREACHABLE;
- return Field::UNUM_FIELD_COUNT; // suppress "control reaches end of non-void function"
}
}
return makeTag(offset, TYPE_CURRENCY_OVERFLOW, STATE_BASE, 0);
default:
UPRV_UNREACHABLE;
- return {-1}; // suppress "control reaches end of non-void function"
}
}
return {3, 3, 1, grouping};
default:
UPRV_UNREACHABLE;
- return {}; // return a value: silence compiler warning
}
}
(void)field;
// This method is not currently used.
UPRV_UNREACHABLE;
- return false;
}
void ConstantAffixModifier::getParameters(Parameters& output) const {
(void)field;
// This method is not currently used.
UPRV_UNREACHABLE;
- return false;
}
void SimpleModifier::getParameters(Parameters& output) const {
(void)field;
// This method is not currently used.
UPRV_UNREACHABLE;
- return false;
}
void MutablePatternModifier::getParameters(Parameters& output) const {
(void)other;
// This method is not currently used.
UPRV_UNREACHABLE;
- return false;
}
int32_t MutablePatternModifier::insertPrefix(NumberStringBuilder& sb, int position, UErrorCode& status) {
return UnicodeString(u"\uFFFD");
default:
UPRV_UNREACHABLE;
- return UnicodeString();
}
}
UnicodeString MutablePatternModifier::toUnicodeString() const {
// Never called by AffixUtils
UPRV_UNREACHABLE;
- return UnicodeString();
}
#endif /* #if !UCONFIG_NO_FORMATTING */
case Precision::RND_CURRENCY:
// Call .withCurrency() before .apply()!
UPRV_UNREACHABLE;
- break;
default:
UPRV_UNREACHABLE;
- break;
}
}
(void)field;
// This method is not used for inner modifiers.
UPRV_UNREACHABLE;
- return false;
}
void ScientificModifier::getParameters(Parameters& output) const {
return Notation::simple();
default:
UPRV_UNREACHABLE;
- return Notation::simple(); // return a value: silence compiler warning
}
}
return NoUnit::permille(); // NOLINT
default:
UPRV_UNREACHABLE;
- return {}; // return a value: silence compiler warning
}
}
return Precision::currency(UCURR_USAGE_CASH);
default:
UPRV_UNREACHABLE;
- return Precision::integer(); // return a value: silence compiler warning
}
}
return UNUM_ROUND_UNNECESSARY;
default:
UPRV_UNREACHABLE;
- return UNUM_ROUND_UNNECESSARY;
}
}
default:
UPRV_UNREACHABLE;
- return STATE_NULL; // return a value: silence compiler warning
}
}
default:
UPRV_UNREACHABLE;
- break;
}
}
return PLURAL_OPERAND_T;
default:
UPRV_UNREACHABLE; // unexpected.
- return PLURAL_OPERAND_N;
}
}
case PLURAL_OPERAND_V: return visibleDecimalDigitCount;
default:
UPRV_UNREACHABLE; // unexpected.
- return source;
}
}
default:
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
- break;
}
if (U_FAILURE(*fStatus)) {
}
if (type < 0 || type > 255) {
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
- type = URX_RESERVED_OP;
}
if (val > 0x00ffffff) {
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
- val = 0;
}
if (val < 0) {
if (!(type == URX_RESERVED_OP_N || type == URX_RESERVED_OP)) {
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
- return -1;
}
if (URX_TYPE(val) != 0xff) {
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
- return -1;
}
type = URX_RESERVED_OP_N;
}
if (c < UCHAR_MIN_VALUE || c > UCHAR_MAX_VALUE) {
// This function should never be called with an invalid input character.
UPRV_UNREACHABLE;
- starterChars->clear();
} else if (u_hasBinaryProperty(c, UCHAR_CASE_SENSITIVE)) {
UChar32 caseFoldedC = u_foldCase(c, U_FOLD_CASE_DEFAULT);
starterChars->set(caseFoldedC, caseFoldedC);
case URX_LBN_END:
UPRV_UNREACHABLE; // Shouldn't get here. These ops should be
// consumed by the scan in URX_LA_START and LB_START
-
- break;
-
default:
UPRV_UNREACHABLE;
}
// These opcodes will be skipped over by code for URX_CRT_INIT.
// We shouldn't encounter them here.
UPRV_UNREACHABLE;
- break;
case URX_LOOP_SR_I:
case URX_LOOP_DOT_I:
// End of look-ahead ops should always be consumed by the processing at
// the URX_LA_START op.
// UPRV_UNREACHABLE;
- // break;
case URX_LB_START:
{
default:
// Some op is unaccounted for.
UPRV_UNREACHABLE;
- error(U_REGEX_INTERNAL_ERROR);
}
}
break;
default:
UPRV_UNREACHABLE;
- break;
}
}
}
}
UPRV_UNREACHABLE;
- return FALSE;
}
}
UPRV_UNREACHABLE;
- return FALSE;
}
break;
default:
UPRV_UNREACHABLE;
- break;
}
}
break;
case RULES:
UPRV_UNREACHABLE; // don't call create() if isRuleBased() returns TRUE!
- break;
}
return t;
}
return 0;
default:
UPRV_UNREACHABLE; // can't get here
- return 0;
}
}
U_NAMESPACE_END
break;
default:
UPRV_UNREACHABLE;
- break;
}
UVector* patternItems = parseOffsetPattern(pattern, required, status);
default:
// Unknown/unsupported argument type.
UPRV_UNREACHABLE;
- *status=U_ILLEGAL_ARGUMENT_ERROR;
- break;
}
}
UnicodeString resultStr;
// understand MeasureFormats, modify this code to do the
// right thing. [alan]
UPRV_UNREACHABLE;
- break;
// better not happen!
case Formattable::kArray:
UPRV_UNREACHABLE;
- break;
}
}
// that is allowed.
if (index != limitIx) {
UPRV_UNREACHABLE;
-
- return NULL;
}
// Manage the circular CE buffer indexing
// that is allowed.
if (index != limitIx) {
UPRV_UNREACHABLE;
-
- return NULL;
}
// Manage the circular CE buffer indexing
}
if (!fDataOwned) {
UPRV_UNREACHABLE;
- status = U_INTERNAL_PROGRAM_ERROR;
- return NULL;
}
numBytes = (numBytes + 15) & ~15; // Round up to a multiple of 16
return u"\uFFFD";
default:
UPRV_UNREACHABLE;
- return {}; // silence compiler warnings
}
}
};