From 832dad561f86220db09c3a1a7bbc75dd5bb0d6a7 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Wed, 27 May 2015 11:18:51 +1000 Subject: [PATCH] Modifications to support aggressive compiler warning levels. These modifications ensure enum.h can be used in a wider selection of end user projects without triggering warnings. GCC 4.9.2 was used with the following warning flags set: -Wall -Wextra -Wshadow -Weffc++ -Wno-unused-parameter -Wno-unused-local-typedefs -Wno-long-long -Wstrict-aliasing -Werror -pedantic -std=c++1y -Wformat=2 -Wmissing-include-dirs -Wsync-nand -Wuninitialized -Wconditionally-supported -Wconversion -Wuseless-cast -Wzero-as-null-pointer-constant This commit includes the modifications required to enable successful use of enum.h via both the "test" and "example" directories. --- enum.h | 20 ++++---- example/1-basic.cc | 2 +- example/2-iterate.cc | 2 +- example/3-switch.cc | 2 +- example/4-constexpr.cc | 2 +- example/5-containers.cc | 2 +- example/6-traits.cc | 6 +-- example/7-bitset.cc | 2 +- example/8-constexpr-iterate.cc | 4 +- test/cxxtest/tests.h | 6 +-- test/link/shared.h | 2 +- test/performance/4-declare_enums.cc | 72 ++++++++++++++--------------- 12 files changed, 61 insertions(+), 61 deletions(-) diff --git a/enum.h b/enum.h index 433cf23..1e7ff86 100644 --- a/enum.h +++ b/enum.h @@ -195,7 +195,7 @@ _ENUM_CONSTEXPR size_t _default() template struct optional { _ENUM_CONSTEXPR optional() : _valid(false), _value(_default()) { } - _ENUM_CONSTEXPR optional(T value) : _valid(true), _value(value) { } + _ENUM_CONSTEXPR optional(T v) : _valid(true), _value(v) { } _ENUM_CONSTEXPR const T& operator *() const { return _value; } _ENUM_CONSTEXPR const T& operator ->() const { return _value; } @@ -221,8 +221,8 @@ template struct _eat_assign { explicit _ENUM_CONSTEXPR _eat_assign(EnumType value) : _value(value) { } template - _ENUM_CONSTEXPR EnumType operator =(Any dummy) const - { return _value; } + _ENUM_CONSTEXPR const _eat_assign& operator =(Any dummy) const + { return *this; } _ENUM_CONSTEXPR operator EnumType () const { return _value; } private: @@ -239,8 +239,8 @@ struct _Iterable { _ENUM_CONSTEXPR const Element& operator [](size_t index) const { return _array[index]; } - _ENUM_CONSTEXPR _Iterable(const Element *array, size_t size) : - _array(array), _size(size) { }; + _ENUM_CONSTEXPR _Iterable(const Element *array, size_t s) : + _array(array), _size(s) { }; private: const Element * const _array; @@ -308,7 +308,7 @@ constexpr char _select(const char *from, size_t from_length, size_t index) constexpr char _toLowercaseAscii(char c) { - return c >= 0x41 && c <= 0x5A ? c + 0x20 : c; + return c >= 0x41 && c <= 0x5A ? (char) (c + 0x20) : c; } constexpr bool _namesMatch(const char *stringizedName, @@ -496,7 +496,7 @@ enum class _Case : Integral { __VA_ARGS__ }; \ \ static_assert(_size > 0, "no constants defined in enum type"); \ \ -_ENUM_TRIM_STRINGS(__VA_ARGS__); \ +_ENUM_TRIM_STRINGS(__VA_ARGS__) \ \ constexpr const char * const _name_array[] = \ { _ENUM_REFER_TO_STRINGS(__VA_ARGS__) }; \ @@ -901,9 +901,9 @@ _ENUM_CONSTEXPR const EnumType operator +(_ENUM_NS(EnumType)::_Base base) \ #define ENUM(EnumType, Integral, ...) \ - _ENUM_DATA(EnumType, Integral, __VA_ARGS__); \ - _ENUM_TYPE(EnumType, Integral, __VA_ARGS__); \ - _ENUM_OPERATORS(EnumType); + _ENUM_DATA(EnumType, Integral, __VA_ARGS__) \ + _ENUM_TYPE(EnumType, Integral, __VA_ARGS__) \ + _ENUM_OPERATORS(EnumType) diff --git a/example/1-basic.cc b/example/1-basic.cc index ca39f6b..1bc0932 100644 --- a/example/1-basic.cc +++ b/example/1-basic.cc @@ -3,7 +3,7 @@ #include #include -ENUM(Channel, uint16_t, Red, Green = 2, Blue, Alias = Red); +ENUM(Channel, uint16_t, Red, Green = 2, Blue, Alias = Red) // Enums should be treated like integers (in memory, Channel is a uint16_t), and // should generally be passed by value. diff --git a/example/2-iterate.cc b/example/2-iterate.cc index 63ce547..2307ca8 100644 --- a/example/2-iterate.cc +++ b/example/2-iterate.cc @@ -3,7 +3,7 @@ #include #include -ENUM(Channel, int, Red = 3, Green = 4, Blue = 0); +ENUM(Channel, int, Red = 3, Green = 4, Blue = 0) int main() { diff --git a/example/3-switch.cc b/example/3-switch.cc index dbab9f4..de6baa5 100644 --- a/example/3-switch.cc +++ b/example/3-switch.cc @@ -3,7 +3,7 @@ #include #include -ENUM(Channel, int, Red, Green, Blue); +ENUM(Channel, int, Red, Green, Blue) void respond_to_channel(Channel channel) { diff --git a/example/4-constexpr.cc b/example/4-constexpr.cc index d2ad456..db85d8e 100644 --- a/example/4-constexpr.cc +++ b/example/4-constexpr.cc @@ -6,7 +6,7 @@ #include #include -ENUM(Channel, int, Red, Green = 2, Blue); +ENUM(Channel, int, Red, Green = 2, Blue) // Initialization. constexpr Channel channel_1 = Channel::Green; diff --git a/example/5-containers.cc b/example/5-containers.cc index 826ce22..367411a 100644 --- a/example/5-containers.cc +++ b/example/5-containers.cc @@ -6,7 +6,7 @@ #include -ENUM(Channel, int, Red, Green, Blue); +ENUM(Channel, int, Red, Green, Blue) int main() { diff --git a/example/6-traits.cc b/example/6-traits.cc index f050f14..c80ec22 100644 --- a/example/6-traits.cc +++ b/example/6-traits.cc @@ -27,11 +27,11 @@ constexpr const Enum default_() // Default will be Red, because it is first. -ENUM(Channel, int, Red, Green, Blue); +ENUM(Channel, int, Red, Green, Blue) // Default will be TrueColor, even though it is not first. -ENUM(Depth, int, HighColor, TrueColor); -ENUM_DEFAULT(Depth, TrueColor); +ENUM(Depth, int, HighColor, TrueColor) +ENUM_DEFAULT(Depth, TrueColor) diff --git a/example/7-bitset.cc b/example/7-bitset.cc index e1a35af..1625841 100644 --- a/example/7-bitset.cc +++ b/example/7-bitset.cc @@ -15,7 +15,7 @@ constexpr Enum maximum(Enum accumulator = Enum::_values[0], size_t index = 1) maximum(accumulator, index + 1); } -ENUM(Channel, int, Red, Green, Blue); +ENUM(Channel, int, Red, Green, Blue) int main() { diff --git a/example/8-constexpr-iterate.cc b/example/8-constexpr-iterate.cc index 756ca9a..405f7cc 100644 --- a/example/8-constexpr-iterate.cc +++ b/example/8-constexpr-iterate.cc @@ -7,8 +7,8 @@ #include #include -ENUM(Channel, int, Red, Green, Blue); -ENUM(Depth, int, TrueColor, HighColor); +ENUM(Channel, int, Red, Green, Blue) +ENUM(Depth, int, TrueColor, HighColor) // Computes the length of a string. constexpr size_t string_length(const char *s, size_t index = 0) diff --git a/test/cxxtest/tests.h b/test/cxxtest/tests.h index 7b96ef4..730e973 100644 --- a/test/cxxtest/tests.h +++ b/test/cxxtest/tests.h @@ -7,9 +7,9 @@ -ENUM(Channel, short, Red, Green, Blue); -ENUM(Depth, short, HighColor = 40, TrueColor = 20); -ENUM(Compression, short, None, Huffman, Default = Huffman); +ENUM(Channel, short, Red, Green, Blue) +ENUM(Depth, short, HighColor = 40, TrueColor = 20) +ENUM(Compression, short, None, Huffman, Default = Huffman) diff --git a/test/link/shared.h b/test/link/shared.h index aed6eb0..5c93cae 100644 --- a/test/link/shared.h +++ b/test/link/shared.h @@ -3,6 +3,6 @@ #include -ENUM(Channel, int, Red, Green, Blue); +ENUM(Channel, int, Red, Green, Blue) #endif // #ifndef _SHARED_H_ diff --git a/test/performance/4-declare_enums.cc b/test/performance/4-declare_enums.cc index 588fa39..b00f351 100644 --- a/test/performance/4-declare_enums.cc +++ b/test/performance/4-declare_enums.cc @@ -1,22 +1,22 @@ #include ENUM(Channel, int, - Red, Green, Blue, Cyan, Magenta, Yellow, Black, Hue, Saturation, Value); + Red, Green, Blue, Cyan, Magenta, Yellow, Black, Hue, Saturation, Value) ENUM(Direction, int, North, East, South, West, NorthEast, SouthEast, SouthWest, NorthWest, NorthNorthEast, EastNorthEast, EastSouthEast, SouthSouthEast, - SouthSouthWest, WestSouthWest, WestNorthWest, NorthNorthWest); + SouthSouthWest, WestSouthWest, WestNorthWest, NorthNorthWest) ENUM(ASTNode, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(State, int, Attacking, Defending, Searching, Pursuing, Hungry, Fleeing, Confused, - Healing, Stunned); + Healing, Stunned) ENUM(APIMethod, int, ReadPost, WritePost, PollPost, ReadImage, WriteImage, PollImage, ReadKey, @@ -25,7 +25,7 @@ ENUM(APIMethod, int, ReadProject, WriteProject, PollProject, ReadComment, WriteComment, PollComment, ReadPermission, WritePermission, PollPermission, ReadOwner, WriteOwner, PollOwner, ReadProposal, WriteProposal, PollProposal, - ReadHistory, WriteHistory, PollHistory); + ReadHistory, WriteHistory, PollHistory) ENUM(Region, int, EasterEurope, CentralEurope, WesternEurope, Mediterranean, NorthAfrica, @@ -38,7 +38,7 @@ ENUM(Region, int, HornOfAfrica, NearEast, AlSham, EastAfrica, NileBasin, Palestine, Levant, Anatolia, AegeanSea, GreatSteppe, CongoBasin, SouthAfrica, WestAfrica, Sahara, WestSahara, NorthwestTerritory, YukonAlaska, Quebec, NewEngland, - DeepSouth); + DeepSouth) int main() { @@ -49,178 +49,178 @@ ENUM(ASTNode0, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode1, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode2, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode3, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode4, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode5, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode6, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode7, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode8, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode9, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode10, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode11, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode12, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode13, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode14, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode15, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode16, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode17, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode18, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode19, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode20, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode21, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode22, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode23, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode24, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode25, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode26, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode27, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode28, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant) ENUM(ASTNode29, int, IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation, BinaryOperation, ApplicationExpression, Abstraction, LetBinding, CaseExpression, Pattern, Signature, Module, Functor, TypeVariable, - BasicType, ArrowType, VariantTypeConstant); + BasicType, ArrowType, VariantTypeConstant)