3

Is the call to f() exception-safe?

inline std::auto_ptr<C> auto_new() {
   return std::auto_ptr<C>(new C());
}

void f(std::auto_ptr<C> p1,
       std::auto_ptr<C> p2);

// ...
{
    f(auto_new(), auto_new());
}

In other words, does it make any difference when it comes to the atomicity of the first and second auto_new() function calls if the two functions are inline?

wilhelmtell
  • 57,473
  • 20
  • 96
  • 131
  • 1
    What confuses you? The `inline`? – sharptooth Jan 19 '11 at 08:43
  • Yeah, it's the `inline` keyword. It means the body of the function can be substituted in-place, which I imagine makes the code look less solid in terms of atomicity. – wilhelmtell Jan 19 '11 at 09:15
  • @wilhelmtell: The _only_ mandated change that happens when you make a function inline are the changes to the _one definition rule_. Everything else may stay exactly the same. – CB Bailey Jan 19 '11 at 09:33
  • @CharlesBailey yes but from that you can deduce _a lot_ more. If the compiler sees the body across compilation units then it means that, well, it can inline the code in situations it wouldn't be able to otherwise. But that has nothing to do with the question. – wilhelmtell Jan 19 '11 at 09:39
  • I'm not sure I understand your point. Initially you seemed to think that `inline` might change the language rules in other ways, I was just trying to be clear about the rules that actually do change. Compilers can do a lot of things but the can't legitimately arbitrarily disregard language rules when they feel like it. – CB Bailey Jan 19 '11 at 09:46
  • @CharlesBailey I understand that. What's wasn't clear to me is what happens to guarantees about exception-safety when a function is inlined. – wilhelmtell Jan 19 '11 at 09:53

1 Answers1

5

Yes, it's exception safe; no, inline makes no difference to the sequence points guaranteed in the calling expression.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • @wilhelmtell: I can't supply a negative reference. If making a function `inline` affected the sequence points in a function call the standard would have to state that somewhere. I'm 99% certain that it doesn't (my search may have failed!) but I can't reference the whole thing to back up my assertion. – CB Bailey Jan 19 '11 at 09:26