0

I have a code similar to this:

std::unique_ptr<Object> get_raii_object()
{
    return std::make_unique<Object>(/* Many parameters that I don't want to write several times, if I remove this function altogether */ );
}

void some_code()
{
    std::unique_ptr<Object> raii_object_holder = get_raii_object();
    more_code();
}

Resharper C++ marks "raii_object_holder" as unused local variable, although it is necessary.

I prefer to avoid disabling this warning, locally, or globally

user972014
  • 3,296
  • 6
  • 49
  • 89
  • it seems to me that you could avoid using unique_ptr altogether since the object merely needs to be constructed and destructed. would that help resharper? – Richard Hodges Aug 08 '15 at 20:09
  • See the comment that I added. It will cause me to copy the ctor params creation to several places. – user972014 Aug 08 '15 at 20:48
  • So far the parser used in ReSharper for C++ is still evolving. If you check out their latest EAP or team blog, you can see examples where huge improvements are coming. Not quite sure if this has been fixed already, but you should report to JetBrains directly. – Lex Li Oct 23 '15 at 22:48

1 Answers1

0

Why not:

class ConfiguredObject : public Object
{
public:
  ConfiguredObject()
    : Object(/* Many parameters that I don't want to write several times, if I remove this function altogether */)
  {}
};

void some_code()
{
  ConfiguredObject object_holder;
}
legalize
  • 2,214
  • 18
  • 25