Skip to content

Commit

Permalink
Bug 1626772 - Fixes for gcc 9 warnings r=botond
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D69275

--HG--
extra : moz-landing-system : lando
  • Loading branch information
hotsphink committed Apr 10, 2020
1 parent 4f03b7c commit 36169fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion js/src/jsapi-tests/testPrintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ static bool MOZ_FORMAT_PRINTF(2, 3)
return output && !strcmp(output.get(), expect);
}

static const char* zero() { return nullptr; }
static const char* zero() {
// gcc 9 is altogether too clever about detecting that this will always
// return nullptr. Do not replace 0x10 with 0x1; it will no longer work.
return uintptr_t(&zero) == 0x10 ? "never happens" : nullptr;
}

BEGIN_TEST(testPrintf) {
CHECK(print_one("23", "%d", 23));
Expand Down
4 changes: 2 additions & 2 deletions js/src/shell/OSObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ JSString* ResolvePath(JSContext* cx, HandleString filenameStr,
// The docs say it can return EINVAL, but the compiler says it's void
_splitpath(scriptFilename.get(), nullptr, buffer, nullptr, nullptr);
#else
strncpy(buffer, scriptFilename.get(), PATH_MAX + 1);
if (buffer[PATH_MAX] != '\0') {
strncpy(buffer, scriptFilename.get(), PATH_MAX);
if (buffer[PATH_MAX - 1] != '\0') {
return nullptr;
}

Expand Down
17 changes: 9 additions & 8 deletions mfbt/DefineEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,29 @@
/*
* A helper macro for asserting that an enumerator does not have an initializer.
*
* The static_assert and the comparison to 0 are just scaffolding; the
* important part is forming the expression |aEnumName::aEnumeratorDecl|.
* The static_assert and the comparison are just scaffolding; the important
* part is forming the expression |aEnumName::aEnumeratorDecl|.
*
* If |aEnumeratorDecl| is just the enumerator name without an identifier,
* this expression compiles fine. However, if |aEnumeratorDecl| includes an
* initializer, as in |eEnumerator = initializer|, then this will fail to
* compile in expression context, since |eEnumerator| is not an lvalue.
*
* (The static_assert itself should always pass in the absence of the above
* error, since you can't get a negative enumerator value without having
* an initializer somewhere. It just provides a place to put the expression
* we want to form.)
* error, since turning on a bit can only increase an integer value. It just
* provides a place to put the expression we want to form.)
*/

#define MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER(aEnumName, aEnumeratorDecl) \
static_assert( \
(aEnumName::aEnumeratorDecl) >= aEnumName(0), \
int(aEnumName::aEnumeratorDecl) <= \
(int(aEnumName::aEnumeratorDecl) | 1), \
"MOZ_DEFINE_ENUM does not allow enumerators to have initializers");

#define MOZ_DEFINE_ENUM_IMPL(aEnumName, aClassSpec, aBaseSpec, aEnumerators) \
enum aClassSpec aEnumName aBaseSpec{MOZ_UNWRAP_ARGS aEnumerators}; \
constexpr size_t k##aEnumName##Count = MOZ_ARG_COUNT aEnumerators; \
constexpr aEnumName k##Highest##aEnumName = \
constexpr aEnumName kHighest##aEnumName = \
aEnumName(k##aEnumName##Count - 1); \
MOZ_FOR_EACH(MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER, (aEnumName, ), \
aEnumerators)
Expand All @@ -132,7 +133,7 @@
aEnumerators) \
enum aClassSpec aEnumName aBaseSpec{MOZ_UNWRAP_ARGS aEnumerators}; \
constexpr static size_t s##aEnumName##Count = MOZ_ARG_COUNT aEnumerators; \
constexpr static aEnumName s##Highest##aEnumName = \
constexpr static aEnumName sHighest##aEnumName = \
aEnumName(s##aEnumName##Count - 1); \
MOZ_FOR_EACH(MOZ_ASSERT_ENUMERATOR_HAS_NO_INITIALIZER, (aEnumName, ), \
aEnumerators)
Expand Down

0 comments on commit 36169fa

Please sign in to comment.