From cc8abe524c572c052dd32b5828c2e7a8c5968c07 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 2 Nov 2024 03:40:18 -0700 Subject: [PATCH] Protect CRTP base classes from improper instantiation --- al/eax/effect.h | 49 +++++++++++++++++++++++++++++++------------------ al/filter.h | 4 ++++ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/al/eax/effect.h b/al/eax/effect.h index 9b1f8bd3..03d97fe5 100644 --- a/al/eax/effect.h +++ b/al/eax/effect.h @@ -1,12 +1,10 @@ #ifndef EAX_EFFECT_INCLUDED #define EAX_EFFECT_INCLUDED - #include #include #include -#include "alnumeric.h" #include "AL/al.h" #include "AL/alext.h" #include "core/effects/base.h" @@ -123,10 +121,6 @@ template struct EaxCommitter { struct Exception; - EaxCommitter(EaxEffectProps &eaxprops, EffectProps &alprops) - : mEaxProps{eaxprops}, mAlProps{alprops} - { } - EaxEffectProps &mEaxProps; EffectProps &mAlProps; @@ -141,10 +135,18 @@ struct EaxCommitter { [[noreturn]] static void fail(const char *message); [[noreturn]] static void fail_unknown_property_id() { fail(EaxEffectErrorMessages::unknown_property_id()); } + +private: + EaxCommitter(EaxEffectProps &eaxprops, EffectProps &alprops) + : mEaxProps{eaxprops}, mAlProps{alprops} + { } + + friend T; }; struct EaxAutowahCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxAutowahCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXAUTOWAHPROPERTIES &props); @@ -153,7 +155,8 @@ struct EaxAutowahCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXAUTOWAHPROPERTIES &props); }; struct EaxChorusCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxChorusCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXCHORUSPROPERTIES &props); @@ -162,7 +165,8 @@ struct EaxChorusCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXCHORUSPROPERTIES &props); }; struct EaxCompressorCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxCompressorCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXAGCCOMPRESSORPROPERTIES &props); @@ -171,7 +175,8 @@ struct EaxCompressorCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXAGCCOMPRESSORPROPERTIES &props); }; struct EaxDistortionCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxDistortionCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXDISTORTIONPROPERTIES &props); @@ -180,7 +185,8 @@ struct EaxDistortionCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXDISTORTIONPROPERTIES &props); }; struct EaxEchoCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxEchoCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXECHOPROPERTIES &props); @@ -189,7 +195,8 @@ struct EaxEchoCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXECHOPROPERTIES &props); }; struct EaxEqualizerCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxEqualizerCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXEQUALIZERPROPERTIES &props); @@ -198,7 +205,8 @@ struct EaxEqualizerCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXEQUALIZERPROPERTIES &props); }; struct EaxFlangerCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxFlangerCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXFLANGERPROPERTIES &props); @@ -207,7 +215,8 @@ struct EaxFlangerCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXFLANGERPROPERTIES &props); }; struct EaxFrequencyShifterCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxFrequencyShifterCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXFREQUENCYSHIFTERPROPERTIES &props); @@ -216,7 +225,8 @@ struct EaxFrequencyShifterCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxModulatorCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXRINGMODULATORPROPERTIES &props); @@ -225,7 +235,8 @@ struct EaxModulatorCommitter : public EaxCommitter { static void Set(const EaxCall &call, EAXRINGMODULATORPROPERTIES &props); }; struct EaxPitchShifterCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxPitchShifterCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXPITCHSHIFTERPROPERTIES &props); @@ -234,7 +245,8 @@ struct EaxPitchShifterCommitter : public EaxCommitter static void Set(const EaxCall &call, EAXPITCHSHIFTERPROPERTIES &props); }; struct EaxVocalMorpherCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxVocalMorpherCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const EAXVOCALMORPHERPROPERTIES &props); @@ -243,7 +255,8 @@ struct EaxVocalMorpherCommitter : public EaxCommitter static void Set(const EaxCall &call, EAXVOCALMORPHERPROPERTIES &props); }; struct EaxNullCommitter : public EaxCommitter { - using EaxCommitter::EaxCommitter; + template + EaxNullCommitter(Args&& ...args) : EaxCommitter{std::forward(args)...} { } bool commit(const std::monostate &props); diff --git a/al/filter.h b/al/filter.h index 562ec52e..d5b20de2 100644 --- a/al/filter.h +++ b/al/filter.h @@ -29,6 +29,10 @@ struct FilterTable { static void getParamiv(const struct ALfilter*, ALenum, int*); static void getParamf(const struct ALfilter*, ALenum, float*); static void getParamfv(const struct ALfilter*, ALenum, float*); + +private: + FilterTable() = default; + friend T; }; struct NullFilterTable : public FilterTable { }; -- 2.11.4.GIT