This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -Wenum-compare and template metaprogramming
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Wed, 3 May 2017 11:26:56 +0100
- Subject: Re: -Wenum-compare and template metaprogramming
- Authentication-results: sourceware.org; auth=none
- References: <1493786479.29093.7.camel@stu.xidian.edu.cn>
On 3 May 2017 at 05:41, Xi Ruoyao wrote:
> In template metaprogramming, we may write something like
>
> ~~~~~
> template <typename A, typename B>
> struct BetterType
> {
> typedef If<(Priority<A>::value > Priority<B>::value), A, B>::type type;
> };
> ~~~~~
>
> However, GCC -Wenum-compare (enabled by default) would complain
> at each POT of BetterType. It seems annoying.
>
> Of course we can cast the operands of compare to int. But should we
> make GCC more clever and not to complain this causal idiom?
You're comparing unrelated enumeration types, which is what the
warning is designed to warn about. Why should it not warn just because
it's in a template?