Skip to content

Commit a1c0e5c

Browse files
committed
clang-tidy: Enable readability-convert-member-functions-to-static
This check finds non-static member functions that can be made static because the functions don’t use this. This check also triggers readability-static-accessed-through -instance check as we are trying to access a static member function through an instance. Change-Id: I887b514a8478abedc24d5495d057b9d3e7dc9bdf Signed-off-by: Pavithra Barithaya <[email protected]>
1 parent b594ac1 commit a1c0e5c

4 files changed

+12
-8
lines changed

.clang-tidy

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ performance-unnecessary-value-param,
245245
readability-avoid-const-params-in-decls,
246246
readability-braces-around-statements,
247247
readability-const-return-type,
248+
readability-convert-member-functions-to-static,
248249
readability-delete-null-pointer,
249250
readability-deleted-default,
250251
readability-function-size,

chassis_state_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class Chassis : public ChassisInherit
234234
*
235235
* @return true if fault detected, else false
236236
*/
237-
bool standbyVoltageRegulatorFault();
237+
static bool standbyVoltageRegulatorFault();
238238

239239
/** @brief Process UPS property changes
240240
*

scheduled_host_transition.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ScheduledHostTransition : public ScheduledHostTransitionInherit
7979
*
8080
* @return - return current epoch time
8181
*/
82-
std::chrono::seconds getTime();
82+
static std::chrono::seconds getTime();
8383

8484
/** @brief Implement host transition
8585
*
@@ -132,7 +132,7 @@ class ScheduledHostTransition : public ScheduledHostTransitionInherit
132132
*
133133
* @return bool - true if successful, false otherwise
134134
*/
135-
bool deserializeScheduledValues(uint64_t& time, Transition& trans);
135+
static bool deserializeScheduledValues(uint64_t& time, Transition& trans);
136136

137137
/** @brief Restore scheduled time and requested transition from persisted
138138
* file */

test/test_scheduled_host_transition.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class TestScheduledHostTransition : public testing::Test
3636
// Empty
3737
}
3838

39-
seconds getCurrentTime()
39+
static seconds getCurrentTime()
4040
{
41-
return scheduledHostTransition.getTime();
41+
return ScheduledHostTransition::getTime();
4242
}
4343

4444
bool isTimerEnabled()
@@ -60,18 +60,20 @@ TEST_F(TestScheduledHostTransition, disableHostTransition)
6060

6161
TEST_F(TestScheduledHostTransition, invalidScheduledTime)
6262
{
63+
seconds currentTime = getCurrentTime();
6364
// scheduled time is 1 min earlier than current time
6465
uint64_t schTime =
65-
static_cast<uint64_t>((getCurrentTime() - seconds(60)).count());
66+
static_cast<uint64_t>((currentTime - seconds(60)).count());
6667
EXPECT_THROW(scheduledHostTransition.scheduledTime(schTime),
6768
InvalidTimeError);
6869
}
6970

7071
TEST_F(TestScheduledHostTransition, validScheduledTime)
7172
{
73+
seconds currentTime = getCurrentTime();
7274
// scheduled time is 1 min later than current time
7375
uint64_t schTime =
74-
static_cast<uint64_t>((getCurrentTime() + seconds(60)).count());
76+
static_cast<uint64_t>((currentTime + seconds(60)).count());
7577
EXPECT_EQ(scheduledHostTransition.scheduledTime(schTime), schTime);
7678
EXPECT_TRUE(isTimerEnabled());
7779
}
@@ -99,9 +101,10 @@ TEST_F(TestScheduledHostTransition, bmcTimeChangeWithDisabledHostTransition)
99101

100102
TEST_F(TestScheduledHostTransition, bmcTimeChangeBackward)
101103
{
104+
seconds currentTime = getCurrentTime();
102105
// Current time is earlier than scheduled time due to BMC time changing
103106
uint64_t schTime =
104-
static_cast<uint64_t>((getCurrentTime() + seconds(60)).count());
107+
static_cast<uint64_t>((currentTime + seconds(60)).count());
105108
// Set scheduled time, which is the same as bmc time is changed.
106109
// But can't use this method to write another case like
107110
// bmcTimeChangeForward, because set a scheduled time earlier than current

0 commit comments

Comments
 (0)