Commit a52b9cd8 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Define symbols properly

The problem popped up when passing the constants by reference
(https://chromium-review.googlesource.com/c/565141).
It's a bit ugly, but, the C++11 standard requires a definition
additionally to the existing declaration in the body of the class:

9.4.2/4: If a static data member is of const literal type, its
  declaration in the class definition can specify a
  brace-or-equal-initializer in which every initializer-clause that is
  an assignment-expression is a constant expression. A static data
  member of literal type can be declared in the class definition with
  the constexpr specifier; if so, its declaration shall specify a
  brace-or-equal-initializer in which every initializer-clause that i
  an assignment-expression is a constant expression. [Note: In both
  these cases, the member may appear in constant expressions. — end
  note] The member shall still be defined in a namespace scope if it is
  odr-used (3.2) in the program and the namespace scope definition shall
  not contain an initializer.

Drive-by: Make the static constants constexpr.

R=bmeurer@chromium.org

Change-Id: Idc3d20bf2adf31d874c23ff8bfec52437789160a
Reviewed-on: https://chromium-review.googlesource.com/567506Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46599}
parent 2ea3b16c
......@@ -95,12 +95,14 @@ template<ElementsKind Kind> class ElementsKindTraits {
typedef FixedArrayBase BackingStore;
};
#define ELEMENTS_TRAITS(Class, KindParam, Store) \
template<> class ElementsKindTraits<KindParam> { \
public: /* NOLINT */ \
static const ElementsKind Kind = KindParam; \
typedef Store BackingStore; \
};
#define ELEMENTS_TRAITS(Class, KindParam, Store) \
template <> \
class ElementsKindTraits<KindParam> { \
public: /* NOLINT */ \
static constexpr ElementsKind Kind = KindParam; \
typedef Store BackingStore; \
}; \
constexpr ElementsKind ElementsKindTraits<KindParam>::Kind;
ELEMENTS_LIST(ELEMENTS_TRAITS)
#undef ELEMENTS_TRAITS
......
......@@ -172,14 +172,18 @@ namespace { // Avoid littering the global namespace.
template <size_t ptr_size> struct SnapshotSizeConstants;
template <> struct SnapshotSizeConstants<4> {
static const int kExpectedHeapGraphEdgeSize = 12;
static const int kExpectedHeapEntrySize = 28;
static constexpr int kExpectedHeapGraphEdgeSize = 12;
static constexpr int kExpectedHeapEntrySize = 28;
};
constexpr int SnapshotSizeConstants<4>::kExpectedHeapGraphEdgeSize;
constexpr int SnapshotSizeConstants<4>::kExpectedHeapEntrySize;
template <> struct SnapshotSizeConstants<8> {
static const int kExpectedHeapGraphEdgeSize = 24;
static const int kExpectedHeapEntrySize = 40;
static constexpr int kExpectedHeapGraphEdgeSize = 24;
static constexpr int kExpectedHeapEntrySize = 40;
};
constexpr int SnapshotSizeConstants<8>::kExpectedHeapGraphEdgeSize;
constexpr int SnapshotSizeConstants<8>::kExpectedHeapEntrySize;
} // namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment