Notice

The forum is in read only mode.

  • Page:
  • 1

TOPIC: C++Builder: Warning in header

C++Builder: Warning in <memory> header 6 years 8 months ago #1915

Hello,

I have the following problem:

I used to follow the guidelines and do my best not to have warnings during compilation (by fixing the code, not by disabling warnings).

Also I use `std::unique_ptr<>`.

But it turned out that implementation of std::unique_ptr has a bug (at least it triggers warning on 32 bit platform in release mode and when I look at implementation it seems, that it is not hundred percent correct).

The specifics. I try to build the following code with 32 bit compiler in release configuration

#include <memory>
using namespace std;

int main()
{
unique_ptr<int> myUniqueInt;
int * myInt = new int(5);
myUniqueInt = unique_ptr<int>(move(myInt));
return 0;
}

Then I get the warning: [bcc32 Warning] memory(806): W8070 Function should return a value

Now if I look to the source of the warning, I see the following (file "memory", line 798, from standard library):

_Myt& operator=(_Myt&& _Right)
{ // assign by moving _Right
if (this != &_Right)
{ // different, do the move
reset(_Right.release());
this->get_deleter() = _STD move(_Right.get_deleter());
return (*this);
}
}

We can see, that indeed if `this == &_Right`, then function does not return any value, so the warning is right.

The questions I have are following:
1. Why the warning is not triggered in the Debug configuration - it is only triggered in release?
2. How can I overcome this without giving up "treat warnings as errors" globally and without disabling this warning globally.

Thanks in advance.
  • Page:
  • 1
Moderators: April Anne