Skip to content

Commit f62fee6

Browse files
committed
Fix: Avoid name shadowing
This patch fixes warnings from Clang due to shadowed names, using three different strategies: 1. **Reuse the shadowed variable.** For the case of a shadowed return code variable, it was safe to reuse the existing return code variable, overwriting it with a different return code. 2. **Rename the shadowing variable.** It is always safe to rename the variable that is causing the shadowing to a more descriptive name. 3. **Follow coding conventions for member variable names.** One warning complained that a parameter to the constructor was shadowing the member variable it was being used to initialize. The member variable should have been prefixed with `d_`, following our coding standards. 4. **Removing the shadowed variable.** For the case of a shadowed storage key variable, it looks like this variable is completely unused, as it is shadowed only a few lines later, without any intermediate references. We can safely remove the original variable. Signed-off-by: Patrick M. Niedzielski <[email protected]>
1 parent ed78d6b commit f62fee6

6 files changed

+21
-19
lines changed

src/applications/bmqstoragetool/m_bmqstoragetool_cslprinter.t.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ static void test1_humanReadableShortResultTest()
7373
// Prepare expected output
7474
bmqu::MemOutStream expectedStream(bmqtst::TestHelperUtil::allocator());
7575
{
76-
bslim::Printer printer(&expectedStream, 0, -1);
77-
printer.start();
78-
printer.printAttribute("recordType", header.recordType());
79-
printer.printAttribute("electorTerm", header.electorTerm());
80-
printer.printAttribute("sequenceNumber", header.sequenceNumber());
81-
printer.printAttribute("timestamp", header.timestamp());
82-
printer.end();
76+
bslim::Printer expectedPrinter(&expectedStream, 0, -1);
77+
expectedPrinter.start();
78+
expectedPrinter.printAttribute("recordType", header.recordType());
79+
expectedPrinter.printAttribute("electorTerm", header.electorTerm());
80+
expectedPrinter.printAttribute("sequenceNumber",
81+
header.sequenceNumber());
82+
expectedPrinter.printAttribute("timestamp", header.timestamp());
83+
expectedPrinter.end();
8384
expectedStream << recordId << '\n';
8485
}
8586

@@ -133,10 +134,12 @@ static void test2_humanReadableDetailResultTest()
133134
bmqu::MemOutStream recordStream(bmqtst::TestHelperUtil::allocator());
134135
record.print(recordStream, 2, 2);
135136

136-
CslRecordPrinter<bmqu::AlignedPrinter> printer(
137+
CslRecordPrinter<bmqu::AlignedPrinter> expectedPrinter(
137138
expectedStream,
138139
bmqtst::TestHelperUtil::allocator());
139-
printer.printRecordDetails(recordStream.str(), header, recordId);
140+
expectedPrinter.printRecordDetails(recordStream.str(),
141+
header,
142+
recordId);
140143
}
141144

142145
BMQTST_ASSERT_EQ(expectedStream.str(), resultStream.str());

src/applications/bmqstoragetool/m_bmqstoragetool_filemanager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ bool FileManagerImpl::CslFileHandler::resetIterator(
271271

272272
if (d_cslFromBegin) {
273273
// Move iterator to the first record.
274-
const int rc = d_iter_p->next();
274+
rc = d_iter_p->next();
275275
if (rc != 0) {
276276
errorDescription << "CSL file either empty or corrupted: rc="
277277
<< rc;

src/applications/bmqstoragetool/m_bmqstoragetool_filters.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ Filters::Filters(const bsl::vector<bsl::string>& queueKeys,
116116
}
117117
}
118118
if (!queueUris.empty()) {
119-
mqbu::StorageKey key;
120119
bsl::vector<bsl::string>::const_iterator uriIt = queueUris.cbegin();
121120
for (; uriIt != queueUris.cend(); ++uriIt) {
122121
bsl::optional<mqbu::StorageKey> key = queueMap.findKeyByUri(

src/applications/bmqstoragetool/m_bmqstoragetool_printer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ void printQueueDetails(bsl::ostream& ostream,
285285
// Sort Apps by number of records ascending
286286
AppsData appsData(allocator);
287287
appsData.reserve(appKeysCount);
288-
for (QueueDetails::AppDetailsMap::const_iterator it =
288+
for (QueueDetails::AppDetailsMap::const_iterator appIt =
289289
details.d_appDetailsMap.cbegin();
290-
it != details.d_appDetailsMap.cend();
291-
++it) {
292-
appsData.emplace_back(it->second.d_recordsNumber,
293-
it->first);
290+
appIt != details.d_appDetailsMap.cend();
291+
++appIt) {
292+
appsData.emplace_back(appIt->second.d_recordsNumber,
293+
appIt->first);
294294
}
295295
bsl::sort(appsData.begin(), appsData.end());
296296

src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ bool SearchResultOffsetDecorator::processDeletionRecord(
254254
bool SearchResultSequenceNumberDecorator::stop(
255255
const CompositeSequenceNumber& sequenceNumber) const
256256
{
257-
return sequenceNumberLt <= sequenceNumber &&
257+
return d_sequenceNumberLt <= sequenceNumber &&
258258
!SearchResultDecorator::hasCache();
259259
}
260260

@@ -263,7 +263,7 @@ SearchResultSequenceNumberDecorator::SearchResultSequenceNumberDecorator(
263263
const CompositeSequenceNumber& sequenceNumberLt,
264264
bslma::Allocator* allocator)
265265
: SearchResultDecorator(component, allocator)
266-
, sequenceNumberLt(sequenceNumberLt)
266+
, d_sequenceNumberLt(sequenceNumberLt)
267267
{
268268
// NOTHING
269269
}

src/applications/bmqstoragetool/m_bmqstoragetool_searchresult.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ class SearchResultOffsetDecorator : public SearchResultDecorator {
554554
class SearchResultSequenceNumberDecorator : public SearchResultDecorator {
555555
private:
556556
/// Higher bound sequence number.
557-
const CompositeSequenceNumber sequenceNumberLt;
557+
const CompositeSequenceNumber d_sequenceNumberLt;
558558

559559
// ACCESSORS
560560

0 commit comments

Comments
 (0)