summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestParamTraitsEnum.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /build/clang-plugin/tests/TestParamTraitsEnum.cpp
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'build/clang-plugin/tests/TestParamTraitsEnum.cpp')
-rw-r--r--build/clang-plugin/tests/TestParamTraitsEnum.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/build/clang-plugin/tests/TestParamTraitsEnum.cpp b/build/clang-plugin/tests/TestParamTraitsEnum.cpp
new file mode 100644
index 0000000000..a250250bfe
--- /dev/null
+++ b/build/clang-plugin/tests/TestParamTraitsEnum.cpp
@@ -0,0 +1,94 @@
+typedef enum {
+ BadFirst,
+ BadSecond,
+ BadThird
+} BadEnum;
+
+typedef enum {
+ NestedFirst,
+ NestedSecond
+} NestedBadEnum;
+
+typedef enum {
+ GoodFirst,
+ GoodSecond,
+ GoodLast
+} GoodEnum;
+
+enum RawEnum {
+ RawFirst,
+ RawLast
+};
+
+enum class ClassEnum {
+ ClassFirst,
+ ClassLast
+};
+
+template <class P> struct ParamTraits;
+
+// Simplified EnumSerializer etc. from IPCMessageUtils.h
+template <typename E, typename EnumValidator>
+struct EnumSerializer {
+ typedef E paramType;
+};
+
+template <typename E,
+ E MinLegal,
+ E HighBound>
+class ContiguousEnumValidator
+{};
+
+template <typename E,
+ E MinLegal,
+ E HighBound>
+struct ContiguousEnumSerializer
+ : EnumSerializer<E,
+ ContiguousEnumValidator<E, MinLegal, HighBound>>
+{};
+
+// Typical ParamTraits implementation that should be avoided
+template<>
+struct ParamTraits<ClassEnum> // expected-error {{Custom ParamTraits implementation for an enum type}} expected-note {{Please use a helper class for example ContiguousEnumSerializer}}
+{
+ typedef ClassEnum paramType;
+};
+
+template<>
+struct ParamTraits<enum RawEnum> // expected-error {{Custom ParamTraits implementation for an enum type}} expected-note {{Please use a helper class for example ContiguousEnumSerializer}}
+{
+ typedef enum RawEnum paramType;
+};
+
+template<>
+struct ParamTraits<BadEnum> // expected-error {{Custom ParamTraits implementation for an enum type}} expected-note {{Please use a helper class for example ContiguousEnumSerializer}}
+{
+ typedef BadEnum paramType;
+};
+
+// Make sure the analysis catches nested typedefs
+typedef NestedBadEnum NestedDefLevel1;
+typedef NestedDefLevel1 NestedDefLevel2;
+
+template<>
+struct ParamTraits<NestedDefLevel2> // expected-error {{Custom ParamTraits implementation for an enum type}} expected-note {{Please use a helper class for example ContiguousEnumSerializer}}
+{
+ typedef NestedDefLevel2 paramType;
+};
+
+// Make sure a non enum typedef is not accidentally flagged
+typedef int IntTypedef;
+
+template<>
+struct ParamTraits<IntTypedef>
+{
+ typedef IntTypedef paramType;
+};
+
+// Make sure ParamTraits using helper classes are not flagged
+template<>
+struct ParamTraits<GoodEnum>
+: public ContiguousEnumSerializer<GoodEnum,
+ GoodEnum::GoodFirst,
+ GoodEnum::GoodLast>
+{};