Skip to content

Commit b8b4ee6

Browse files
[Support] Add [[nodiscard]] (NFC)
1 parent d9a0163 commit b8b4ee6

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

llvm/include/llvm/Support/Endian.h

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ constexpr endianness system_endianness() {
4646
}
4747

4848
template <typename value_type>
49-
inline value_type byte_swap(value_type value, endianness endian) {
49+
[[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) {
5050
if ((endian != native) && (endian != system_endianness()))
5151
sys::swapByteOrder(value);
5252
return value;
5353
}
5454

5555
/// Swap the bytes of value to match the given endianness.
56-
template<typename value_type, endianness endian>
57-
inline value_type byte_swap(value_type value) {
56+
template <typename value_type, endianness endian>
57+
[[nodiscard]] inline value_type byte_swap(value_type value) {
5858
return byte_swap(value, endian);
5959
}
6060

6161
/// Read a value of a particular endianness from memory.
6262
template <typename value_type, std::size_t alignment = unaligned>
63-
inline value_type read(const void *memory, endianness endian) {
63+
[[nodiscard]] inline value_type read(const void *memory, endianness endian) {
6464
value_type ret;
6565

6666
memcpy(&ret,
@@ -70,25 +70,24 @@ inline value_type read(const void *memory, endianness endian) {
7070
return byte_swap<value_type>(ret, endian);
7171
}
7272

73-
template<typename value_type,
74-
endianness endian,
75-
std::size_t alignment>
76-
inline value_type read(const void *memory) {
73+
template <typename value_type, endianness endian, std::size_t alignment>
74+
[[nodiscard]] inline value_type read(const void *memory) {
7775
return read<value_type, alignment>(memory, endian);
7876
}
7977

8078
/// Read a value of a particular endianness from a buffer, and increment the
8179
/// buffer past that value.
8280
template <typename value_type, std::size_t alignment, typename CharT>
83-
inline value_type readNext(const CharT *&memory, endianness endian) {
81+
[[nodiscard]] inline value_type readNext(const CharT *&memory,
82+
endianness endian) {
8483
value_type ret = read<value_type, alignment>(memory, endian);
8584
memory += sizeof(value_type);
8685
return ret;
8786
}
8887

89-
template<typename value_type, endianness endian, std::size_t alignment,
90-
typename CharT>
91-
inline value_type readNext(const CharT *&memory) {
88+
template <typename value_type, endianness endian, std::size_t alignment,
89+
typename CharT>
90+
[[nodiscard]] inline value_type readNext(const CharT *&memory) {
9291
return readNext<value_type, alignment, CharT>(memory, endian);
9392
}
9493

@@ -114,7 +113,8 @@ using make_unsigned_t = std::make_unsigned_t<value_type>;
114113
/// Read a value of a particular endianness from memory, for a location
115114
/// that starts at the given bit offset within the first byte.
116115
template <typename value_type, endianness endian, std::size_t alignment>
117-
inline value_type readAtBitAlignment(const void *memory, uint64_t startBit) {
116+
[[nodiscard]] inline value_type readAtBitAlignment(const void *memory,
117+
uint64_t startBit) {
118118
assert(startBit < 8);
119119
if (startBit == 0)
120120
return read<value_type, endian, alignment>(memory);
@@ -349,36 +349,42 @@ using aligned_big_t = detail::packed_endian_specific_integral<T, big, aligned>;
349349

350350
namespace endian {
351351

352-
template <typename T, endianness E> inline T read(const void *P) {
352+
template <typename T, endianness E> [[nodiscard]] inline T read(const void *P) {
353353
return *(const detail::packed_endian_specific_integral<T, E, unaligned> *)P;
354354
}
355355

356-
inline uint16_t read16(const void *P, endianness E) {
356+
[[nodiscard]] inline uint16_t read16(const void *P, endianness E) {
357357
return read<uint16_t>(P, E);
358358
}
359-
inline uint32_t read32(const void *P, endianness E) {
359+
[[nodiscard]] inline uint32_t read32(const void *P, endianness E) {
360360
return read<uint32_t>(P, E);
361361
}
362-
inline uint64_t read64(const void *P, endianness E) {
362+
[[nodiscard]] inline uint64_t read64(const void *P, endianness E) {
363363
return read<uint64_t>(P, E);
364364
}
365365

366-
template <endianness E> inline uint16_t read16(const void *P) {
366+
template <endianness E> [[nodiscard]] inline uint16_t read16(const void *P) {
367367
return read<uint16_t, E>(P);
368368
}
369-
template <endianness E> inline uint32_t read32(const void *P) {
369+
template <endianness E> [[nodiscard]] inline uint32_t read32(const void *P) {
370370
return read<uint32_t, E>(P);
371371
}
372-
template <endianness E> inline uint64_t read64(const void *P) {
372+
template <endianness E> [[nodiscard]] inline uint64_t read64(const void *P) {
373373
return read<uint64_t, E>(P);
374374
}
375375

376-
inline uint16_t read16le(const void *P) { return read16<little>(P); }
377-
inline uint32_t read32le(const void *P) { return read32<little>(P); }
378-
inline uint64_t read64le(const void *P) { return read64<little>(P); }
379-
inline uint16_t read16be(const void *P) { return read16<big>(P); }
380-
inline uint32_t read32be(const void *P) { return read32<big>(P); }
381-
inline uint64_t read64be(const void *P) { return read64<big>(P); }
376+
[[nodiscard]] inline uint16_t read16le(const void *P) {
377+
return read16<little>(P);
378+
}
379+
[[nodiscard]] inline uint32_t read32le(const void *P) {
380+
return read32<little>(P);
381+
}
382+
[[nodiscard]] inline uint64_t read64le(const void *P) {
383+
return read64<little>(P);
384+
}
385+
[[nodiscard]] inline uint16_t read16be(const void *P) { return read16<big>(P); }
386+
[[nodiscard]] inline uint32_t read32be(const void *P) { return read32<big>(P); }
387+
[[nodiscard]] inline uint64_t read64be(const void *P) { return read64<big>(P); }
382388

383389
template <typename T, endianness E> inline void write(void *P, T V) {
384390
*(detail::packed_endian_specific_integral<T, E, unaligned> *)P = V;

0 commit comments

Comments
 (0)