Friend function is unable to construct a unique pointer of the class

Here is another approach I've seen used, apparently known as the passkey idiom : have the public constructor require a private access token.

class Spam {
    struct Token {};
    friend void Foo();
public:
    Spam(Token, int mem) : mem(mem) {}

private:
    int mem;
};

void Foo() {
    std::unique_ptr<Spam> spam = std::make_unique<Spam>(Spam::Token{}, 10);
}

void Bar() {
    // error: 'Spam::Token Spam::token' is private
    // std::unique_ptr<Spam> spam = std::make_unique<Spam>(Spam::Token{}, 10);
}

In your case the function make_unique is trying to create an instance of Spam and that function is not a friend. Calling a non-friend function from inside a friend function does not imbue the non-friend function with friend status.

To solve this you can write in Foo:

std::unique_ptr<Spam> spam(new Spam(10));