Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A18-9-4
#2
The short (and unhelpful) answer is that the rule only talks about uses of std::foward, and this doesn't appear in your example, so as far as the example is concerned, the rule doesn't apply.  Its a general principle that rules don't consider how library functions may be implemented.

We believe that the intent was to limit use after std::foward  'within the same function body, not in general'. So, even if there is a std::forward inside std::make_unique, your example is still OK (apart from the fact it doesn't compile - Foo needs a copy constructor).

The following example may clarify further:

#include <utility>

template <typename T> void foo (T && arg)
    {
      auto j = std::forward<T> (arg);
      // non-compliant to use 'arg' here
    }

void bar ()
    {
      int i = 0;
      foo (i);
      ++i;                // Compliant
      foo (std::move(i));
      ++i;                // Rule A18-9-4 doesn't apply, but
                              // non-compliant with A12-8-3 because
                              // of read of moved from object
    }
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Messages In This Thread
A18-9-4 - by cgpzs - 15-10-2024, 09:58 AM
RE: A18-9-4 - by misra cpp - 22-10-2024, 02:18 PM
RE: A18-9-4 - by cgpzs - 23-10-2024, 12:04 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)