When object constructed in argument is destructed, before of after function call?

E.g. is the following code safe?

```
void f(const char*)
{ ... }

std::string g()
{ ... }
...
f(g().c_str());

```

It always works for me but I don't know is it just undefined behaviour or it actually should work.