clang-tidy: Enable cppcoreguidelines-pro-type-reinterpret-cast

There are ways to avoid reinterpret_cast<>() in many circumstances.
For libpldm, often its use can be replaced with placement-new.
Enable the lint for reinterpret_cast<>() to prevent its use in future
changes. This way we can stay inside the language rather than rely on
implementation-defined behavior.

Existing uses of reinterpret_cast<>() are marked NOLINT for now, with
the intent that we clean them up over time. The insertion of the NOLINTs
was automated with sed.

Change-Id: If6654f774e438de9262fe9f9012c6b574764c326
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/tests/dsp/pdr.cpp b/tests/dsp/pdr.cpp
index b8e224e..ef6e4e8 100644
--- a/tests/dsp/pdr.cpp
+++ b/tests/dsp/pdr.cpp
@@ -272,6 +272,7 @@
 
     std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123};
     uint32_t handle = 1;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()),
                            sizeof(in), false, 1, &handle),
               0);
@@ -306,14 +307,17 @@
     std::array<uint32_t, 10> in2{1000, 3450, 30,  60,     890,
                                  0,    110,  450, 234034, 123123};
     handle = 2;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), false, 1, &handle),
               0);
     handle = 3;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), false, 1, &handle),
               0);
     handle = 4;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), true, 1, &handle),
               0);
@@ -362,6 +366,7 @@
 
     std::array<uint32_t, 10> in{100, 345, 3, 6, 89, 0, 11, 45, 23434, 123123};
     uint32_t handle = 1;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in.data()),
                            sizeof(in), false, 1, &handle),
               0);
@@ -380,14 +385,17 @@
     std::array<uint32_t, 10> in2{1000, 3450, 30,  60,     890,
                                  0,    110,  450, 234034, 123123};
     handle = 2;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), false, 1, &handle),
               0);
     handle = 3;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), false, 1, &handle),
               0);
     handle = 4;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<uint8_t*>(in2.data()),
                            sizeof(in2), false, 1, &handle),
               0);
@@ -420,6 +428,7 @@
     auto repo = pldm_pdr_init();
 
     std::array<uint8_t, sizeof(pldm_pdr_hdr)> data{};
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(data.data());
     hdr->type = 1;
     uint32_t first = 0;
@@ -493,11 +502,13 @@
     EXPECT_NE(hdl, nullptr);
     EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set));
     EXPECT_EQ(nextRecHdl, 0u);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
     EXPECT_EQ(hdr->version, 1u);
     EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
     EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
     EXPECT_EQ(hdr->record_handle, htole32(1));
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_fru_record_set* fru = reinterpret_cast<pldm_pdr_fru_record_set*>(
         outData + sizeof(pldm_pdr_hdr));
     EXPECT_EQ(fru->terminus_handle, htole16(1));
@@ -517,11 +528,13 @@
     EXPECT_NE(hdl, nullptr);
     EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set));
     EXPECT_EQ(nextRecHdl, 0u);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
     EXPECT_EQ(hdr->version, 1u);
     EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
     EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
     EXPECT_EQ(hdr->record_handle, htole32(2));
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData +
                                                      sizeof(pldm_pdr_hdr));
     EXPECT_EQ(fru->terminus_handle, htole16(2));
@@ -535,11 +548,13 @@
     EXPECT_NE(hdl, nullptr);
     EXPECT_EQ(size, sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_fru_record_set));
     EXPECT_EQ(nextRecHdl, 2u);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
     EXPECT_EQ(hdr->version, 1u);
     EXPECT_EQ(hdr->type, PLDM_PDR_FRU_RECORD_SET);
     EXPECT_EQ(hdr->length, htole16(sizeof(pldm_pdr_fru_record_set)));
     EXPECT_EQ(hdr->record_handle, htole32(1));
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     fru = reinterpret_cast<pldm_pdr_fru_record_set*>(outData +
                                                      sizeof(pldm_pdr_hdr));
     EXPECT_EQ(fru->terminus_handle, htole16(1));
@@ -635,18 +650,21 @@
 
     hdr.type = 1;
     uint16_t firstTerminusHandle = 1;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<const uint8_t*>(&hdr),
                            sizeof(hdr), false, firstTerminusHandle, NULL),
               0);
 
     hdr.type = 2;
     uint16_t secondTerminusHandle = 2;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<const uint8_t*>(&hdr),
                            sizeof(hdr), true, secondTerminusHandle, NULL),
               0);
 
     hdr.type = 3;
     uint16_t thirdTerminusHandle = 3;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     EXPECT_EQ(pldm_pdr_add(repo, reinterpret_cast<const uint8_t*>(&hdr),
                            sizeof(hdr), true, thirdTerminusHandle, NULL),
               0);
@@ -1180,16 +1198,19 @@
                                       l1, PLDM_ENTITY_ASSOCIAION_LOGICAL) *
                                   sizeof(pldm_entity)));
     uint8_t* start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 1u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     uint16_t* containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 1u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_entity* entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 1u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1198,11 +1219,13 @@
     EXPECT_EQ(*start,
               pldm_entity_get_num_children(l1, PLDM_ENTITY_ASSOCIAION_LOGICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 3u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
     EXPECT_EQ(le16toh(entity->entity_container_id), 1u);
     start += sizeof(pldm_entity);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 3u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 2u);
@@ -1215,16 +1238,19 @@
                                       l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL) *
                                   sizeof(pldm_entity)));
     start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 2u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 1u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 1u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1233,11 +1259,13 @@
     EXPECT_EQ(*start, pldm_entity_get_num_children(
                           l1, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 2u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
     EXPECT_EQ(le16toh(entity->entity_container_id), 1u);
     start += sizeof(pldm_entity);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 2u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 2u);
@@ -1250,16 +1278,19 @@
                                       l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL) *
                                   sizeof(pldm_entity)));
     start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 3u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 2u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 2u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1268,11 +1299,13 @@
     EXPECT_EQ(*start, pldm_entity_get_num_children(
                           l2a, PLDM_ENTITY_ASSOCIAION_LOGICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 5);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 2u);
     EXPECT_EQ(le16toh(entity->entity_container_id), 2u);
     start += sizeof(pldm_entity);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 5u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 3u);
@@ -1285,16 +1318,19 @@
                                       l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) *
                                   sizeof(pldm_entity)));
     start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 4u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 2u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 2u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1303,11 +1339,13 @@
     EXPECT_EQ(*start, pldm_entity_get_num_children(
                           l2a, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 4u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
     EXPECT_EQ(le16toh(entity->entity_container_id), 2u);
     start += sizeof(pldm_entity);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 5u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1320,16 +1358,19 @@
                                       l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL) *
                                   sizeof(pldm_entity)));
     start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 5u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 3u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_PHYSICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 4u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1338,6 +1379,7 @@
     EXPECT_EQ(*start, pldm_entity_get_num_children(
                           l3a, PLDM_ENTITY_ASSOCIAION_PHYSICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 6u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1350,16 +1392,19 @@
                                       l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL) *
                                   sizeof(pldm_entity)));
     start = data;
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     hdr = reinterpret_cast<pldm_pdr_hdr*>(start);
     EXPECT_EQ(le32toh(hdr->record_handle), 6u);
     EXPECT_EQ(hdr->type, PLDM_PDR_ENTITY_ASSOCIATION);
     EXPECT_EQ(le16toh(hdr->length), size - sizeof(struct pldm_pdr_hdr));
     start += sizeof(pldm_pdr_hdr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     containerId = reinterpret_cast<uint16_t*>(start);
     EXPECT_EQ(le16toh(*containerId), 4u);
     start += sizeof(uint16_t);
     EXPECT_EQ(*start, PLDM_ENTITY_ASSOCIAION_LOGICAL);
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 5u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1368,6 +1413,7 @@
     EXPECT_EQ(*start, pldm_entity_get_num_children(
                           l3b, PLDM_ENTITY_ASSOCIAION_LOGICAL));
     start += sizeof(uint8_t);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     entity = reinterpret_cast<pldm_entity*>(start);
     EXPECT_EQ(le16toh(entity->entity_type), 7u);
     EXPECT_EQ(le16toh(entity->entity_instance_num), 1u);
@@ -1516,12 +1562,14 @@
     std::vector<uint8_t> pdr{};
     pdr.resize(sizeof(pldm_pdr_hdr) + sizeof(pldm_pdr_entity_association) +
                sizeof(pldm_entity) * 4);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(pdr.data());
     hdr->type = PLDM_PDR_ENTITY_ASSOCIATION;
     hdr->length =
         htole16(sizeof(pldm_pdr_entity_association) + sizeof(pldm_entity) * 4);
 
     pldm_pdr_entity_association* e =
+        // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
         reinterpret_cast<pldm_pdr_entity_association*>(pdr.data() +
                                                        sizeof(pldm_pdr_hdr));
     e->container_id = htole16(1);
@@ -1869,12 +1917,14 @@
     outData = nullptr;
     auto hdl1 = pldm_pdr_find_record(repo, 2, &outData, &size, &nextRecHdl);
     EXPECT_NE(hdl1, nullptr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr = reinterpret_cast<pldm_pdr_hdr*>(outData);
     EXPECT_EQ(hdr->record_handle, 2);
 
     outData = nullptr;
     auto hdl2 = pldm_pdr_find_record(repo, 23, &outData, &size, &nextRecHdl);
     EXPECT_NE(hdl2, nullptr);
+    // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
     pldm_pdr_hdr* hdr1 = reinterpret_cast<pldm_pdr_hdr*>(outData);
     EXPECT_EQ(hdr1->record_handle, 23);