summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp
diff options
context:
space:
mode:
authoryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 23:21:54 +0000
committeryzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 23:21:54 +0000
commitdfe815b7e8d2ad1818e89a4c1bb7a3ace701fd00 (patch)
tree717cd97bc05c710e2a0c69fc161cef4882abd3e6 /ppapi/cpp
parentab714ec7b7607024b5f3daca855a479191ca7986 (diff)
downloadchromium_src-dfe815b7e8d2ad1818e89a4c1bb7a3ace701fd00.zip
chromium_src-dfe815b7e8d2ad1818e89a4c1bb7a3ace701fd00.tar.gz
chromium_src-dfe815b7e8d2ad1818e89a4c1bb7a3ace701fd00.tar.bz2
Fix IsBaseOf in output_traits.h.
Previously, it may be used with forward declarations unintentionally and does wrong things silently. BUG=None TEST=None Review URL: http://codereview.chromium.org/10068004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132088 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/cpp')
-rw-r--r--ppapi/cpp/dev/audio_input_dev.h5
-rw-r--r--ppapi/cpp/output_traits.h8
2 files changed, 8 insertions, 5 deletions
diff --git a/ppapi/cpp/dev/audio_input_dev.h b/ppapi/cpp/dev/audio_input_dev.h
index 2b2b6bb..1c80f4d 100644
--- a/ppapi/cpp/dev/audio_input_dev.h
+++ b/ppapi/cpp/dev/audio_input_dev.h
@@ -59,11 +59,6 @@ class AudioInput_Dev : public Resource {
/// struct.
const AudioConfig& config() const { return config_; }
- // TODO(yzshen, brettw): If we forward declare DeviceRef_Dev (as opposed to
- // including its .h file), it still compiles. However, it is not recognized as
- // a derived class of Resource and does the wrong thing!
- // This is due to the limitation of IsBaseOf in ppapi/cpp/output_traits.h. We
- // need to figure out a way to overcome this problem.
int32_t EnumerateDevices(
const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >&
callback);
diff --git a/ppapi/cpp/output_traits.h b/ppapi/cpp/output_traits.h
index 963f296..5b45aa47e 100644
--- a/ppapi/cpp/output_traits.h
+++ b/ppapi/cpp/output_traits.h
@@ -35,9 +35,17 @@ template<typename A> struct IsSame<A, A> {
static bool const value = true;
};
template<typename Base, typename Derived> struct IsBaseOf {
+ private:
+ // This class doesn't work correctly with forward declarations.
+ // Because sizeof cannot be applied to incomplete types, this line prevents us
+ // from passing in forward declarations.
+ typedef char (*EnsureTypesAreComplete)[sizeof(Base) + sizeof(Derived)];
+
static Derived* CreateDerived();
static char (&Check(Base*))[1];
static char (&Check(...))[2];
+
+ public:
static bool const value = sizeof Check(CreateDerived()) == 1 &&
!IsSame<Base const, void const>::value;
};