Commit 0fc5f9d3 authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

[base] Broaden Singleton's friend declarations

Friend'ing specific methods is incorrect since the addition of
GetIfExits() because, although clang compiles this without warnings,
the spec clearly says that friend'ing an undeclared method is not
allowed (even if no such method ever exists and hence never uses that
friend declaration). Not nearly all singletons need to support
GetInstanceIfExists() and hence adding everywhere is undesired.

This CL makes Singleton<T> friend all of T. This is fine because
that doesn't give much more power to T (beyond the option of naming
its GetInstance() method differently...).

Bug: 905990
Change-Id: I2d2c721b27f8f3fa3367dff996f37293c98674c3
Reviewed-on: https://chromium-review.googlesource.com/c/1343660Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609809}
parent 8e6a1ba0
......@@ -219,12 +219,10 @@ template <typename Type,
typename DifferentiatingType = Type>
class Singleton {
private:
// Classes using the Singleton<T> pattern should declare a GetInstance()
// method and call Singleton::get() from within that.
friend Type* Type::GetInstance();
// Classes may also declare a GetInstanceIfExists() method to invoke
// Singleton::GetIfExists().
friend Type* Type::GetInstanceIfExists();
// A class T using the Singleton<T> pattern should declare a GetInstance()
// method and call Singleton::get() from within that. T may also declare a
// GetInstanceIfExists() method to invoke Singleton::GetIfExists().
friend Type;
// This class is safe to be constructed and copy-constructed since it has no
// member.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment