From 0e1dd874f84a29af7ee2fd8dd04766bc777035cf Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 4 Jun 2012 19:27:12 +0000 Subject: [PATCH] re PR c++/53524 (Bogus enum comparison warning) 2012-06-04 Paolo Carlini PR c++/53524 * doc/invoke.texi (Wenum-compare): Update documentation. /cp 2012-06-04 Paolo Carlini PR c++/53524 * call.c (build_conditional_expr_1): Use OPT_Wenum_compare to control enumeral mismatch in conditional expression too. /testsuite 2012-06-04 Paolo Carlini PR c++/53524 * g++.dg/warn/Wenum-compare-no-2: New. From-SVN: r188204 --- gcc/ChangeLog | 5 +++ gcc/cp/ChangeLog | 6 ++++ gcc/cp/call.c | 2 +- gcc/doc/invoke.texi | 7 +++-- gcc/testsuite/ChangeLog | 5 +++ .../g++.dg/warn/Wenum-compare-no-2.C | 31 +++++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wenum-compare-no-2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9448591306e..54db10a1e44 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-06-04 Paolo Carlini + + PR c++/53524 + * doc/invoke.texi (Wenum-compare): Update documentation. + 2012-06-04 Dodji Seketeli PR preprocessor/53463 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1a2f8e6c39f..f473e2ce159 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-06-04 Paolo Carlini + + PR c++/53524 + * call.c (build_conditional_expr_1): Use OPT_Wenum_compare + to control enumeral mismatch in conditional expression too. + 2012-06-04 Steven Bosscher * semantics.c: Do not include output.h. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 6745afd379d..ad31f6a1c87 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4696,7 +4696,7 @@ build_conditional_expr_1 (tree arg1, tree arg2, tree arg3, && TREE_CODE (arg3_type) == ENUMERAL_TYPE) { if (complain & tf_warning) - warning (0, + warning (OPT_Wenum_compare, "enumeral mismatch in conditional expression: %qT vs %qT", arg2_type, arg3_type); } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d4f22e84df7..40c0838466e 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -4297,9 +4297,10 @@ while} statement. This warning is also enabled by @option{-Wextra}. @item -Wenum-compare @opindex Wenum-compare @opindex Wno-enum-compare -Warn about a comparison between values of different enumerated types. In C++ -this warning is enabled by default. In C this warning is enabled by -@option{-Wall}. +Warn about a comparison between values of different enumerated types. +In C++ enumeral mismatches in conditional expressions are also +diagnosed and the warning is enabled by default. In C this warning is +enabled by @option{-Wall}. @item -Wjump-misses-init @r{(C, Objective-C only)} @opindex Wjump-misses-init diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2d125fcebea..c2d248052a1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-06-04 Paolo Carlini + + PR c++/53524 + * g++.dg/warn/Wenum-compare-no-2: New. + 2012-06-04 Dodji Seketeli PR preprocessor/53463 diff --git a/gcc/testsuite/g++.dg/warn/Wenum-compare-no-2.C b/gcc/testsuite/g++.dg/warn/Wenum-compare-no-2.C new file mode 100644 index 00000000000..fa7dda88a3e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wenum-compare-no-2.C @@ -0,0 +1,31 @@ +// PR c++/53524 +// { dg-options "-Wno-enum-compare" } + +template < typename > struct PointerLikeTypeTraits { + enum { NumLowBitsAvailable }; +}; + +class CodeGenInstruction; +class CodeGenInstAlias; + +template < typename T> +struct PointerIntPair { + enum { IntShift = T::NumLowBitsAvailable }; +}; + +template < typename PT1, typename PT2 > struct PointerUnionUIntTraits { + enum { + PT1BitsAv = PointerLikeTypeTraits < PT1 >::NumLowBitsAvailable, + PT2BitsAv = PointerLikeTypeTraits < PT2 >::NumLowBitsAvailable, + NumLowBitsAvailable = 0 ? PT1BitsAv : PT2BitsAv + }; +}; + +template < typename PT1, typename PT2 > class PointerUnion { + typedef PointerIntPair < PointerUnionUIntTraits < PT1, PT2 > > ValTy; + ValTy Val; +}; + +struct ClassInfo { + PointerUnion < CodeGenInstruction *, CodeGenInstAlias * > DefRec; +}; -- 2.30.2