Skip to content

Commit 6c4cb6f

Browse files
Googlera-maurice
authored andcommitted
LSC: Mark static const class/struct members as constexpr. This change fixes declarations that have initial values but are technically not definitions by marking them constexpr (which counts as a definition). This enables, among other things, the modified constants to be passed into functions and function templates that accept arguments by reference. Without this change, such functions would cause linker errors.
This change was approved as part of go/static-const-lsc. Tested: tap_presubmit Some tests failed; test failures are believed to be unrelated to this CL PiperOrigin-RevId: 307464964
1 parent a52f2e9 commit 6c4cb6f

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

app/memory/atomic.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,27 @@ namespace compat {
3535
// in length.`
3636
template <typename T>
3737
struct CanBeAtomic {
38-
static const bool value = false;
38+
static constexpr bool value = false;
3939
};
4040

4141
template <>
4242
struct CanBeAtomic<int32_t> {
43-
static const bool value = true;
43+
static constexpr bool value = true;
4444
};
4545

4646
template <>
4747
struct CanBeAtomic<uint32_t> {
48-
static const bool value = true;
48+
static constexpr bool value = true;
4949
};
5050

5151
template <>
5252
struct CanBeAtomic<int64_t> {
53-
static const bool value = true;
53+
static constexpr bool value = true;
5454
};
5555

5656
template <>
5757
struct CanBeAtomic<uint64_t> {
58-
static const bool value = true;
58+
static constexpr bool value = true;
5959
};
6060

6161
// Provides a minimal atomic counter, required to implement SharedPtr.

app/meta/type_traits.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,27 @@ struct remove_reference<T&&> {
4242

4343
template <typename T>
4444
struct is_array {
45-
static const bool value = false;
45+
static constexpr bool value = false;
4646
};
4747

4848
template <typename T>
4949
struct is_array<T[]> {
50-
static const bool value = true;
50+
static constexpr bool value = true;
5151
};
5252

5353
template <typename T, std::size_t N>
5454
struct is_array<T[N]> {
55-
static const bool value = true;
55+
static constexpr bool value = true;
5656
};
5757

5858
template <typename T>
5959
struct is_lvalue_reference {
60-
static const bool value = false;
60+
static constexpr bool value = false;
6161
};
6262

6363
template <typename T>
6464
struct is_lvalue_reference<T&> {
65-
static const bool value = true;
65+
static constexpr bool value = true;
6666
};
6767

6868
// NOLINTNEXTLINE - allow namespace overridden

app/src/include/firebase/variant.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ class Variant {
11391139
char small_string[sizeof(BlobValue)];
11401140
} value_;
11411141

1142-
static const size_t kMaxSmallStringSize = sizeof(Value::small_string);
1142+
static constexpr size_t kMaxSmallStringSize = sizeof(Value::small_string);
11431143

11441144
friend class firebase::internal::VariantInternal;
11451145
};

app/src/reference_counted_future_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ class ReferenceCountedFutureImpl : public detail::FutureApiInterface {
100100
public:
101101
/// This handle will never be returned by @ref Alloc, so you can use it
102102
/// to signify an uninitialized or invalid value.
103-
static const FutureHandle kInvalidHandle = kInvalidFutureHandle;
103+
static constexpr FutureHandle kInvalidHandle = kInvalidFutureHandle;
104104

105105
/// Returned by @ref GetFutureError when the passed in handle is invalid.
106-
static const int kErrorFutureIsNoLongerValid = -1;
106+
static constexpr int kErrorFutureIsNoLongerValid = -1;
107107

108108
/// Returned by @ref GetFutureErrorMessage when the passed in handle is
109109
/// invalid.
110110
static const char kErrorMessageFutureIsNoLongerValid[];
111111

112112
/// Pass into @ref Alloc for `fn_idx` when you don't want to update any
113113
/// function.
114-
static const int kNoFunctionIndex = -1;
114+
static constexpr int kNoFunctionIndex = -1;
115115

116116
explicit ReferenceCountedFutureImpl(size_t last_result_count)
117117
: next_future_handle_(kInvalidHandle + 1),

database/src/desktop/push_child_name_generator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ class PushChildNameGenerator {
3232

3333
private:
3434
static const char* const kPushChars;
35-
static const int kNumPushChars = 64;
36-
static const int kNumTimestampChars = 8;
37-
static const int kNumRandomChars = 12;
38-
static const int kGeneratedNameLength = kNumTimestampChars + kNumRandomChars;
35+
static constexpr int kNumPushChars = 64;
36+
static constexpr int kNumTimestampChars = 8;
37+
static constexpr int kNumRandomChars = 12;
38+
static constexpr int kGeneratedNameLength =
39+
kNumTimestampChars + kNumRandomChars;
3940

4041
// For random number generation.
4142
std::random_device random_device_;

0 commit comments

Comments
 (0)