Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e4764e9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add SIZEOF_MEMBER."

parents 1b2f2ee6 1b86d41c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ cc_test {
        "errors_test.cpp",
        "file_test.cpp",
        "logging_test.cpp",
        "macros_test.cpp",
        "parsedouble_test.cpp",
        "parseint_test.cpp",
        "parsenetaddress_test.cpp",
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <stddef.h>  // for size_t
#include <unistd.h>  // for TEMP_FAILURE_RETRY

#include <utility>

// bionic and glibc both have TEMP_FAILURE_RETRY, but eg Mac OS' libc doesn't.
#ifndef TEMP_FAILURE_RETRY
#define TEMP_FAILURE_RETRY(exp)            \
@@ -114,6 +116,8 @@ char(&ArraySizeHelper(T(&array)[N]))[N]; // NOLINT(readability/casting)
  ((sizeof(a) / sizeof(*(a))) / \
    static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))

#define SIZEOF_MEMBER(t, f) sizeof(std::declval<t>().f)

// Changing this definition will cause you a lot of pain.  A majority of
// vendor code defines LIKELY and UNLIKELY this way, and includes
// this header through an indirect path.

base/macros_test.cpp

0 → 100644
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "android-base/macros.h"

#include <stdint.h>

#include <gtest/gtest.h>

TEST(macros, SIZEOF_MEMBER_macro) {
  struct S {
    int32_t i32;
    double d;
  };
  ASSERT_EQ(4U, SIZEOF_MEMBER(S, i32));
  ASSERT_EQ(8U, SIZEOF_MEMBER(S, d));
}