Skip to content

Commit

Permalink
COMP: Fix set but not used warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hjmjohnson committed Nov 25, 2024
1 parent 99453ef commit 41505ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/Core/Common/ReturnObjectFromFunction/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,28 @@ main()
std::cout << smartPointer->GetLargestPossibleRegion() << std::endl;
}

// Common failure modes
{
ImageType * pointer = ReturnPointer();
// This crashes the program because the smart pointer created in the function goes out of scope and gets deleted
// because it is returned as a normal pointer.

// ImageType * pointer = ReturnPointer();
// std::cout << pointer->GetLargestPossibleRegion() << std::endl;
pointer = nullptr; // Here to silence warning
}

{
ImageType * pointer = ReturnSmartPointer();
// This crashes the program because though the function returned a ::Pointer, it was not stored
// anywhere so the reference count was not increased, so it got deleted.

// ImageType * pointer = ReturnSmartPointer();
// std::cout << pointer->GetLargestPossibleRegion() << std::endl;
pointer = nullptr; // Here to silence warning
}

{
// I thought this might also work, but it does not (crash).
// My reasoning was that even though you don't return a smart pointer, you assign the object to a smart
// pointer at return time, so it still has a reference count of 1.

// ImageType::Pointer smartPointer = ReturnPointer(); // this line causes a 'glibc error'
// std::cout << smartPointer->GetLargestPossibleRegion() << std::endl;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Mesh/AccessDataInCells/Code.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ main(int, char *[])

while (cellDataIterator != end)
{
PixelType cellValue = cellDataIterator.Value();
// std::cout << cellValue << std::endl; //same values as before
const auto cellValue = cellDataIterator.Value();
std::cout << cellValue << std::endl; // same values as before
++cellDataIterator;
}

Expand Down

0 comments on commit 41505ad

Please sign in to comment.