From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- gcc/testsuite/g++.dg/warn/Wall-write-strings.C | 7 + gcc/testsuite/g++.dg/warn/Walways-true-1.C | 57 +++++ gcc/testsuite/g++.dg/warn/Walways-true-2.C | 60 +++++ gcc/testsuite/g++.dg/warn/Warray-bounds-2.C | 13 ++ gcc/testsuite/g++.dg/warn/Warray-bounds-3.C | 15 ++ gcc/testsuite/g++.dg/warn/Warray-bounds-4.C | 37 +++ gcc/testsuite/g++.dg/warn/Warray-bounds-5.C | 24 ++ gcc/testsuite/g++.dg/warn/Warray-bounds.C | 92 ++++++++ gcc/testsuite/g++.dg/warn/Wbraces1.C | 3 + gcc/testsuite/g++.dg/warn/Wbraces2.C | 15 ++ gcc/testsuite/g++.dg/warn/Wcast-qual1.C | 7 + gcc/testsuite/g++.dg/warn/Wcast-qual2.C | 167 +++++++++++++ gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C | 15 ++ gcc/testsuite/g++.dg/warn/Wchar-subscripts.C | 12 + gcc/testsuite/g++.dg/warn/Wconversion-integer.C | 94 ++++++++ gcc/testsuite/g++.dg/warn/Wconversion-null-2.C | 49 ++++ gcc/testsuite/g++.dg/warn/Wconversion-null.C | 49 ++++ gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C | 54 +++++ .../g++.dg/warn/Wconversion-real-integer.C | 112 +++++++++ gcc/testsuite/g++.dg/warn/Wconversion-real.C | 0 gcc/testsuite/g++.dg/warn/Wconversion1.C | 12 + gcc/testsuite/g++.dg/warn/Wconversion2.C | 3 + gcc/testsuite/g++.dg/warn/Wconversion3.C | 35 +++ gcc/testsuite/g++.dg/warn/Wctor-dtor.C | 13 ++ gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C | 7 + gcc/testsuite/g++.dg/warn/Wdouble-promotion.C | 99 ++++++++ gcc/testsuite/g++.dg/warn/Wdtor1.C | 22 ++ gcc/testsuite/g++.dg/warn/Weff1.C | 5 + gcc/testsuite/g++.dg/warn/Wenum-compare-no.C | 10 + gcc/testsuite/g++.dg/warn/Wenum-compare.C | 10 + gcc/testsuite/g++.dg/warn/Wextra-1.C | 12 + gcc/testsuite/g++.dg/warn/Wextra-2.C | 15 ++ gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C | 10 + gcc/testsuite/g++.dg/warn/Winline-1.C | 10 + gcc/testsuite/g++.dg/warn/Winline-2.C | 5 + gcc/testsuite/g++.dg/warn/Winline-3.C | 10 + gcc/testsuite/g++.dg/warn/Winline-4.C | 17 ++ gcc/testsuite/g++.dg/warn/Wlogical-op-1.C | 66 ++++++ .../g++.dg/warn/Wmissing-declarations-1.C | 45 ++++ gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C | 8 + gcc/testsuite/g++.dg/warn/Wnvdtor-2.C | 54 +++++ gcc/testsuite/g++.dg/warn/Wnvdtor.C | 10 + gcc/testsuite/g++.dg/warn/Woverflow-1.C | 7 + gcc/testsuite/g++.dg/warn/Woverflow-2.C | 7 + gcc/testsuite/g++.dg/warn/Woverflow-3.C | 7 + gcc/testsuite/g++.dg/warn/Woverloaded-1.C | 17 ++ gcc/testsuite/g++.dg/warn/Wparentheses-1.C | 68 ++++++ gcc/testsuite/g++.dg/warn/Wparentheses-10.C | 119 ++++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-11.C | 101 ++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-12.C | 60 +++++ gcc/testsuite/g++.dg/warn/Wparentheses-13.C | 69 ++++++ gcc/testsuite/g++.dg/warn/Wparentheses-14.C | 43 ++++ gcc/testsuite/g++.dg/warn/Wparentheses-15.C | 68 ++++++ gcc/testsuite/g++.dg/warn/Wparentheses-16.C | 86 +++++++ gcc/testsuite/g++.dg/warn/Wparentheses-17.C | 32 +++ gcc/testsuite/g++.dg/warn/Wparentheses-18.C | 122 ++++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-19.C | 122 ++++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-2.C | 43 ++++ gcc/testsuite/g++.dg/warn/Wparentheses-20.C | 104 +++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-21.C | 66 ++++++ gcc/testsuite/g++.dg/warn/Wparentheses-22.C | 111 +++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-23.C | 121 ++++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-24.C | 14 ++ gcc/testsuite/g++.dg/warn/Wparentheses-25.C | 259 +++++++++++++++++++++ gcc/testsuite/g++.dg/warn/Wparentheses-3.C | 13 ++ gcc/testsuite/g++.dg/warn/Wparentheses-4.C | 19 ++ gcc/testsuite/g++.dg/warn/Wparentheses-5.C | 12 + gcc/testsuite/g++.dg/warn/Wparentheses-6.C | 65 ++++++ gcc/testsuite/g++.dg/warn/Wparentheses-7.C | 83 +++++++ gcc/testsuite/g++.dg/warn/Wparentheses-8.C | 29 +++ gcc/testsuite/g++.dg/warn/Wparentheses-9.C | 119 ++++++++++ gcc/testsuite/g++.dg/warn/Wreorder-1.C | 14 ++ gcc/testsuite/g++.dg/warn/Wreturn-1.C | 9 + gcc/testsuite/g++.dg/warn/Wreturn-2.C | 7 + gcc/testsuite/g++.dg/warn/Wreturn-3.C | 18 ++ gcc/testsuite/g++.dg/warn/Wreturn-type-1.C | 11 + gcc/testsuite/g++.dg/warn/Wreturn-type-2.C | 20 ++ gcc/testsuite/g++.dg/warn/Wreturn-type-3.C | 14 ++ gcc/testsuite/g++.dg/warn/Wreturn-type-4.C | 43 ++++ gcc/testsuite/g++.dg/warn/Wreturn-type-5.C | 21 ++ gcc/testsuite/g++.dg/warn/Wreturn-type-6.C | 13 ++ gcc/testsuite/g++.dg/warn/Wsequence-point-1.C | 11 + gcc/testsuite/g++.dg/warn/Wsequence-point-2.C | 28 +++ gcc/testsuite/g++.dg/warn/Wsequence-point-3.C | 20 ++ .../g++.dg/warn/Wsequence-point-pr18050.C | 24 ++ gcc/testsuite/g++.dg/warn/Wshadow-1.C | 41 ++++ gcc/testsuite/g++.dg/warn/Wshadow-2.C | 10 + gcc/testsuite/g++.dg/warn/Wshadow-3.C | 8 + gcc/testsuite/g++.dg/warn/Wshadow-4.C | 32 +++ gcc/testsuite/g++.dg/warn/Wshadow-5.C | 33 +++ gcc/testsuite/g++.dg/warn/Wshadow-6.C | 39 ++++ gcc/testsuite/g++.dg/warn/Wshadow-7.C | 37 +++ gcc/testsuite/g++.dg/warn/Wsign-compare-1.C | 6 + gcc/testsuite/g++.dg/warn/Wsign-compare-2.C | 10 + gcc/testsuite/g++.dg/warn/Wsign-compare-3.C | 13 ++ gcc/testsuite/g++.dg/warn/Wsign-conversion.C | 95 ++++++++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-1.C | 9 + gcc/testsuite/g++.dg/warn/Wstrict-aliasing-2.C | 13 ++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-3.C | 14 ++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-4.C | 13 ++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-5.C | 9 + gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C | 9 + gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C | 20 ++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C | 20 ++ .../warn/Wstrict-aliasing-bogus-base-derived.C | 21 ++ .../g++.dg/warn/Wstrict-aliasing-bogus-char-1.C | 10 + .../g++.dg/warn/Wstrict-aliasing-bogus-const.C | 9 + .../g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C | 19 ++ .../g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C | 35 +++ .../g++.dg/warn/Wstrict-aliasing-bogus-escape.C | 30 +++ .../warn/Wstrict-aliasing-bogus-nested-arrays.C | 9 + .../warn/Wstrict-aliasing-bogus-placement-new.C | 29 +++ .../warn/Wstrict-aliasing-bogus-signed-unsigned.C | 10 + .../warn/Wstrict-aliasing-bogus-struct-included.C | 16 ++ .../g++.dg/warn/Wstrict-aliasing-bogus-union.C | 15 ++ .../warn/Wstrict-aliasing-float-ref-int-obj.C | 12 + .../g++.dg/warn/Wstring-literal-comparison-1.C | 29 +++ .../g++.dg/warn/Wstring-literal-comparison-2.C | 29 +++ .../g++.dg/warn/Wstring-literal-comparison-3.C | 29 +++ .../g++.dg/warn/Wstring-literal-comparison-4.C | 29 +++ gcc/testsuite/g++.dg/warn/Wswitch-1.C | 63 +++++ gcc/testsuite/g++.dg/warn/Wswitch-2.C | 31 +++ gcc/testsuite/g++.dg/warn/Wswitch-3.C | 37 +++ gcc/testsuite/g++.dg/warn/Wswitch-default-1.C | 22 ++ gcc/testsuite/g++.dg/warn/Wswitch-default-2.C | 21 ++ gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C | 84 +++++++ gcc/testsuite/g++.dg/warn/Wtype-limits-no.C | 84 +++++++ gcc/testsuite/g++.dg/warn/Wtype-limits.C | 84 +++++++ .../g++.dg/warn/Wuninitializable-member-no.C | 15 ++ .../g++.dg/warn/Wuninitializable-member.C | 14 ++ gcc/testsuite/g++.dg/warn/Wuninitialized-1.C | 15 ++ gcc/testsuite/g++.dg/warn/Wuninitialized-2.C | 53 +++++ gcc/testsuite/g++.dg/warn/Wuninitialized-3.C | 17 ++ gcc/testsuite/g++.dg/warn/Wuninitialized-4.C | 22 ++ gcc/testsuite/g++.dg/warn/Wuninitialized-5.C | 22 ++ gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C | 22 ++ gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C | 23 ++ gcc/testsuite/g++.dg/warn/Wunused-1.C | 15 ++ gcc/testsuite/g++.dg/warn/Wunused-10.C | 8 + gcc/testsuite/g++.dg/warn/Wunused-11.C | 11 + gcc/testsuite/g++.dg/warn/Wunused-12.C | 8 + gcc/testsuite/g++.dg/warn/Wunused-13.C | 7 + gcc/testsuite/g++.dg/warn/Wunused-14.C | 14 ++ gcc/testsuite/g++.dg/warn/Wunused-15.C | 11 + gcc/testsuite/g++.dg/warn/Wunused-16.C | 9 + gcc/testsuite/g++.dg/warn/Wunused-17.C | 19 ++ gcc/testsuite/g++.dg/warn/Wunused-2.C | 6 + gcc/testsuite/g++.dg/warn/Wunused-3.C | 11 + gcc/testsuite/g++.dg/warn/Wunused-4.C | 30 +++ gcc/testsuite/g++.dg/warn/Wunused-5.C | 19 ++ gcc/testsuite/g++.dg/warn/Wunused-6.C | 11 + gcc/testsuite/g++.dg/warn/Wunused-7.C | 12 + gcc/testsuite/g++.dg/warn/Wunused-8.C | 9 + gcc/testsuite/g++.dg/warn/Wunused-9.C | 38 +++ gcc/testsuite/g++.dg/warn/Wunused-label-1.C | 28 +++ gcc/testsuite/g++.dg/warn/Wunused-label-2.C | 13 ++ gcc/testsuite/g++.dg/warn/Wunused-label-3.C | 51 ++++ gcc/testsuite/g++.dg/warn/Wunused-parm-1.C | 58 +++++ gcc/testsuite/g++.dg/warn/Wunused-parm-2.C | 54 +++++ gcc/testsuite/g++.dg/warn/Wunused-parm-3.C | 71 ++++++ gcc/testsuite/g++.dg/warn/Wunused-parm-4.C | 24 ++ gcc/testsuite/g++.dg/warn/Wunused-var-1.C | 8 + gcc/testsuite/g++.dg/warn/Wunused-var-10.C | 42 ++++ gcc/testsuite/g++.dg/warn/Wunused-var-11.C | 33 +++ gcc/testsuite/g++.dg/warn/Wunused-var-12.C | 36 +++ gcc/testsuite/g++.dg/warn/Wunused-var-13.C | 22 ++ gcc/testsuite/g++.dg/warn/Wunused-var-14.C | 17 ++ gcc/testsuite/g++.dg/warn/Wunused-var-15.C | 29 +++ gcc/testsuite/g++.dg/warn/Wunused-var-2.C | 104 +++++++++ gcc/testsuite/g++.dg/warn/Wunused-var-3.C | 110 +++++++++ gcc/testsuite/g++.dg/warn/Wunused-var-4.C | 50 ++++ gcc/testsuite/g++.dg/warn/Wunused-var-5.C | 227 ++++++++++++++++++ gcc/testsuite/g++.dg/warn/Wunused-var-6.C | 29 +++ gcc/testsuite/g++.dg/warn/Wunused-var-7.C | 48 ++++ gcc/testsuite/g++.dg/warn/Wunused-var-8.C | 46 ++++ gcc/testsuite/g++.dg/warn/Wunused-var-9.C | 13 ++ gcc/testsuite/g++.dg/warn/Wvla-1.C | 7 + gcc/testsuite/g++.dg/warn/Wvla-2.C | 7 + gcc/testsuite/g++.dg/warn/Wvla-3.C | 7 + gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C | 18 ++ gcc/testsuite/g++.dg/warn/anonymous-namespace-1.h | 7 + gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C | 29 +++ gcc/testsuite/g++.dg/warn/anonymous-namespace-2.h | 3 + gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C | 13 ++ gcc/testsuite/g++.dg/warn/anonymous-namespace-3.h | 1 + gcc/testsuite/g++.dg/warn/changes-meaning.C | 11 + gcc/testsuite/g++.dg/warn/compare1.C | 10 + gcc/testsuite/g++.dg/warn/conv1.C | 33 +++ gcc/testsuite/g++.dg/warn/conv2.C | 5 + gcc/testsuite/g++.dg/warn/conv3.C | 4 + gcc/testsuite/g++.dg/warn/conv4.C | 22 ++ gcc/testsuite/g++.dg/warn/conversion-function-1.C | 8 + gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-1.C | 9 + gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-2.C | 7 + gcc/testsuite/g++.dg/warn/ctor-init-1.C | 9 + gcc/testsuite/g++.dg/warn/ctor1.C | 13 ++ gcc/testsuite/g++.dg/warn/deprecated-2.C | 11 + gcc/testsuite/g++.dg/warn/deprecated-3.C | 14 ++ gcc/testsuite/g++.dg/warn/deprecated-4.C | 9 + gcc/testsuite/g++.dg/warn/deprecated-5.C | 4 + gcc/testsuite/g++.dg/warn/deprecated-6.C | 110 +++++++++ gcc/testsuite/g++.dg/warn/deprecated.C | 117 ++++++++++ gcc/testsuite/g++.dg/warn/do-empty.C | 15 ++ gcc/testsuite/g++.dg/warn/effc1.C | 16 ++ gcc/testsuite/g++.dg/warn/effc2.C | 39 ++++ gcc/testsuite/g++.dg/warn/effc3.C | 58 +++++ gcc/testsuite/g++.dg/warn/empty-body.C | 12 + gcc/testsuite/g++.dg/warn/format1.C | 15 ++ gcc/testsuite/g++.dg/warn/format2.C | 32 +++ gcc/testsuite/g++.dg/warn/format3.C | 12 + gcc/testsuite/g++.dg/warn/format4.C | 13 ++ gcc/testsuite/g++.dg/warn/forward-inner.C | 81 +++++++ gcc/testsuite/g++.dg/warn/friend.C | 14 ++ gcc/testsuite/g++.dg/warn/huge-val1.C | 33 +++ gcc/testsuite/g++.dg/warn/if-empty-1.C | 23 ++ gcc/testsuite/g++.dg/warn/ignored_typedef.C | 22 ++ gcc/testsuite/g++.dg/warn/implicit-typename1.C | 17 ++ gcc/testsuite/g++.dg/warn/implicit-typename2.C | 12 + gcc/testsuite/g++.dg/warn/implicit-typename3.C | 12 + gcc/testsuite/g++.dg/warn/incomplete1.C | 22 ++ gcc/testsuite/g++.dg/warn/incomplete2.C | 13 ++ gcc/testsuite/g++.dg/warn/inline1.C | 23 ++ gcc/testsuite/g++.dg/warn/inline2.C | 20 ++ gcc/testsuite/g++.dg/warn/main-2.C | 19 ++ gcc/testsuite/g++.dg/warn/main-3.C | 7 + gcc/testsuite/g++.dg/warn/main-4.C | 5 + gcc/testsuite/g++.dg/warn/main.C | 11 + gcc/testsuite/g++.dg/warn/miss-format-1.C | 43 ++++ gcc/testsuite/g++.dg/warn/miss-format-2.C | 17 ++ gcc/testsuite/g++.dg/warn/miss-format-3.C | 27 +++ gcc/testsuite/g++.dg/warn/miss-format-4.C | 33 +++ gcc/testsuite/g++.dg/warn/miss-format-5.C | 49 ++++ gcc/testsuite/g++.dg/warn/miss-format-6.C | 32 +++ gcc/testsuite/g++.dg/warn/missing-field-init-1.C | 9 + gcc/testsuite/g++.dg/warn/missing-field-init-2.C | 9 + .../g++.dg/warn/multiple-overflow-warn-1.C | 13 ++ .../g++.dg/warn/multiple-overflow-warn-2.C | 12 + .../g++.dg/warn/multiple-overflow-warn-3.C | 12 + gcc/testsuite/g++.dg/warn/new1.C | 3 + gcc/testsuite/g++.dg/warn/no-write-strings.C | 7 + gcc/testsuite/g++.dg/warn/noeffect2.C | 20 ++ gcc/testsuite/g++.dg/warn/noeffect4.C | 88 +++++++ gcc/testsuite/g++.dg/warn/noeffect5.C | 8 + gcc/testsuite/g++.dg/warn/noeffect6.C | 14 ++ gcc/testsuite/g++.dg/warn/noeffect7.C | 8 + gcc/testsuite/g++.dg/warn/noeffect8.C | 15 ++ gcc/testsuite/g++.dg/warn/nonnull1.C | 16 ++ gcc/testsuite/g++.dg/warn/noreturn-1.C | 71 ++++++ gcc/testsuite/g++.dg/warn/noreturn-2.C | 4 + gcc/testsuite/g++.dg/warn/noreturn-3.C | 13 ++ gcc/testsuite/g++.dg/warn/noreturn-4.C | 13 ++ gcc/testsuite/g++.dg/warn/noreturn-5.C | 15 ++ gcc/testsuite/g++.dg/warn/noreturn-6.C | 13 ++ gcc/testsuite/g++.dg/warn/noreturn-7.C | 15 ++ gcc/testsuite/g++.dg/warn/null4.C | 55 +++++ gcc/testsuite/g++.dg/warn/oldcast1.C | 16 ++ gcc/testsuite/g++.dg/warn/overflow-warn-1.C | 128 ++++++++++ gcc/testsuite/g++.dg/warn/overflow-warn-3.C | 130 +++++++++++ gcc/testsuite/g++.dg/warn/overflow-warn-4.C | 133 +++++++++++ gcc/testsuite/g++.dg/warn/overflow-warn-5.C | 11 + gcc/testsuite/g++.dg/warn/overflow-warn-6.C | 18 ++ gcc/testsuite/g++.dg/warn/pedantic1.C | 11 + gcc/testsuite/g++.dg/warn/pedantic2.C | 10 + gcc/testsuite/g++.dg/warn/pmf1.C | 18 ++ .../g++.dg/warn/pointer-integer-comparison.C | 26 +++ gcc/testsuite/g++.dg/warn/pr11159.C | 37 +++ gcc/testsuite/g++.dg/warn/pr11492.C | 12 + gcc/testsuite/g++.dg/warn/pr12242.C | 57 +++++ gcc/testsuite/g++.dg/warn/pr13358-2.C | 24 ++ gcc/testsuite/g++.dg/warn/pr13358-3.C | 24 ++ gcc/testsuite/g++.dg/warn/pr13358-4.C | 24 ++ gcc/testsuite/g++.dg/warn/pr13358.C | 24 ++ gcc/testsuite/g++.dg/warn/pr15774-1.C | 15 ++ gcc/testsuite/g++.dg/warn/pr15774-2.C | 15 ++ gcc/testsuite/g++.dg/warn/pr16302.C | 76 ++++++ gcc/testsuite/g++.dg/warn/pr21983.C | 7 + gcc/testsuite/g++.dg/warn/pr23075.C | 9 + gcc/testsuite/g++.dg/warn/pr26785.C | 10 + gcc/testsuite/g++.dg/warn/pr28943.C | 15 ++ gcc/testsuite/g++.dg/warn/pr30551-2.C | 6 + gcc/testsuite/g++.dg/warn/pr30551.C | 6 + gcc/testsuite/g++.dg/warn/pr30636.C | 17 ++ gcc/testsuite/g++.dg/warn/pr31246-2.C | 9 + gcc/testsuite/g++.dg/warn/pr31246.C | 10 + gcc/testsuite/g++.dg/warn/pr33160.C | 12 + gcc/testsuite/g++.dg/warn/pr33738.C | 26 +++ gcc/testsuite/g++.dg/warn/pr34985.C | 9 + gcc/testsuite/g++.dg/warn/pr35602.C | 28 +++ gcc/testsuite/g++.dg/warn/pr35635.C | 89 +++++++ gcc/testsuite/g++.dg/warn/pr35711.C | 8 + gcc/testsuite/g++.dg/warn/pr36069.C | 16 ++ gcc/testsuite/g++.dg/warn/pr36921.C | 27 +++ gcc/testsuite/g++.dg/warn/pr36954.C | 23 ++ gcc/testsuite/g++.dg/warn/pr36999.C | 40 ++++ gcc/testsuite/g++.dg/warn/pr5310.C | 11 + gcc/testsuite/g++.dg/warn/pr5645.C | 32 +++ gcc/testsuite/g++.dg/warn/pr8570.C | 13 ++ gcc/testsuite/g++.dg/warn/pr8715.C | 11 + gcc/testsuite/g++.dg/warn/pragma-system_header1.C | 10 + gcc/testsuite/g++.dg/warn/pragma-system_header1.h | 7 + gcc/testsuite/g++.dg/warn/pragma-system_header2.C | 17 ++ gcc/testsuite/g++.dg/warn/pragma-system_header2.h | 5 + gcc/testsuite/g++.dg/warn/pragma-system_header3.C | 9 + gcc/testsuite/g++.dg/warn/pragma-system_header3.h | 7 + gcc/testsuite/g++.dg/warn/pragma-system_header4.C | 6 + gcc/testsuite/g++.dg/warn/pragma-system_header4.h | 2 + gcc/testsuite/g++.dg/warn/pragma-system_header5.C | 10 + gcc/testsuite/g++.dg/warn/pragma-system_header5.h | 3 + gcc/testsuite/g++.dg/warn/private1.C | 16 ++ gcc/testsuite/g++.dg/warn/register-var-1.C | 14 ++ gcc/testsuite/g++.dg/warn/register-var-2.C | 14 ++ gcc/testsuite/g++.dg/warn/return-reference.C | 21 ++ gcc/testsuite/g++.dg/warn/return-reference2.C | 21 ++ gcc/testsuite/g++.dg/warn/sentinel.C | 11 + gcc/testsuite/g++.dg/warn/sequence-pt-1.C | 109 +++++++++ gcc/testsuite/g++.dg/warn/sequence-pt-2.C | 46 ++++ gcc/testsuite/g++.dg/warn/sequence-pt-3.C | 15 ++ gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C | 54 +++++ gcc/testsuite/g++.dg/warn/skip-1.C | 17 ++ gcc/testsuite/g++.dg/warn/skip-2.C | 37 +++ gcc/testsuite/g++.dg/warn/string1.C | 18 ++ gcc/testsuite/g++.dg/warn/switch1.C | 15 ++ gcc/testsuite/g++.dg/warn/template-1.C | 15 ++ gcc/testsuite/g++.dg/warn/translate-ice-1.C | 45 ++++ gcc/testsuite/g++.dg/warn/undefined1.C | 7 + gcc/testsuite/g++.dg/warn/unit-1.C | 10 + gcc/testsuite/g++.dg/warn/unused-result1-Werror.c | 11 + gcc/testsuite/g++.dg/warn/unused-result1.C | 10 + gcc/testsuite/g++.dg/warn/var-args1.C | 11 + gcc/testsuite/g++.dg/warn/volatile1.C | 12 + gcc/testsuite/g++.dg/warn/weak1.C | 22 ++ gcc/testsuite/g++.dg/warn/write-strings-default.C | 7 + gcc/testsuite/g++.dg/warn/write-strings.C | 7 + 333 files changed, 9893 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wall-write-strings.C create mode 100644 gcc/testsuite/g++.dg/warn/Walways-true-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Walways-true-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Warray-bounds.C create mode 100644 gcc/testsuite/g++.dg/warn/Wbraces1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wbraces2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wcast-qual1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wcast-qual2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wchar-subscripts.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-integer.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-null-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-null.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-real.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wctor-dtor.C create mode 100644 gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C create mode 100644 gcc/testsuite/g++.dg/warn/Wdouble-promotion.C create mode 100644 gcc/testsuite/g++.dg/warn/Wdtor1.C create mode 100644 gcc/testsuite/g++.dg/warn/Weff1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wenum-compare-no.C create mode 100644 gcc/testsuite/g++.dg/warn/Wenum-compare.C create mode 100644 gcc/testsuite/g++.dg/warn/Wextra-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wextra-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Winline-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Winline-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Winline-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Winline-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wlogical-op-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C create mode 100644 gcc/testsuite/g++.dg/warn/Wnvdtor-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wnvdtor.C create mode 100644 gcc/testsuite/g++.dg/warn/Woverflow-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Woverflow-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Woverflow-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Woverloaded-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-10.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-11.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-12.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-13.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-14.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-15.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-16.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-17.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-18.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-19.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-20.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-21.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-22.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-23.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-24.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-25.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-8.C create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-9.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreorder-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-type-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsequence-point-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsequence-point-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsequence-point-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsequence-point-pr18050.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wshadow-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-compare-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-compare-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-compare-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-conversion.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-base-derived.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-const.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-nested-arrays.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-placement-new.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-signed-unsigned.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-struct-included.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstrict-aliasing-float-ref-int-obj.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-default-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wswitch-default-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C create mode 100644 gcc/testsuite/g++.dg/warn/Wtype-limits-no.C create mode 100644 gcc/testsuite/g++.dg/warn/Wtype-limits.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitializable-member.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wuninitialized-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-10.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-11.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-12.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-13.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-14.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-15.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-16.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-17.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-8.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-9.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-label-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-label-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-label-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-parm-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-10.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-11.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-12.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-13.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-14.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-15.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-3.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-4.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-5.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-6.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-7.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-8.C create mode 100644 gcc/testsuite/g++.dg/warn/Wunused-var-9.C create mode 100644 gcc/testsuite/g++.dg/warn/Wvla-1.C create mode 100644 gcc/testsuite/g++.dg/warn/Wvla-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wvla-3.C create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-1.h create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-2.h create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C create mode 100644 gcc/testsuite/g++.dg/warn/anonymous-namespace-3.h create mode 100644 gcc/testsuite/g++.dg/warn/changes-meaning.C create mode 100644 gcc/testsuite/g++.dg/warn/compare1.C create mode 100644 gcc/testsuite/g++.dg/warn/conv1.C create mode 100644 gcc/testsuite/g++.dg/warn/conv2.C create mode 100644 gcc/testsuite/g++.dg/warn/conv3.C create mode 100644 gcc/testsuite/g++.dg/warn/conv4.C create mode 100644 gcc/testsuite/g++.dg/warn/conversion-function-1.C create mode 100644 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-1.C create mode 100644 gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-2.C create mode 100644 gcc/testsuite/g++.dg/warn/ctor-init-1.C create mode 100644 gcc/testsuite/g++.dg/warn/ctor1.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-2.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-3.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-4.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-5.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated-6.C create mode 100644 gcc/testsuite/g++.dg/warn/deprecated.C create mode 100644 gcc/testsuite/g++.dg/warn/do-empty.C create mode 100644 gcc/testsuite/g++.dg/warn/effc1.C create mode 100644 gcc/testsuite/g++.dg/warn/effc2.C create mode 100644 gcc/testsuite/g++.dg/warn/effc3.C create mode 100644 gcc/testsuite/g++.dg/warn/empty-body.C create mode 100644 gcc/testsuite/g++.dg/warn/format1.C create mode 100644 gcc/testsuite/g++.dg/warn/format2.C create mode 100644 gcc/testsuite/g++.dg/warn/format3.C create mode 100644 gcc/testsuite/g++.dg/warn/format4.C create mode 100644 gcc/testsuite/g++.dg/warn/forward-inner.C create mode 100644 gcc/testsuite/g++.dg/warn/friend.C create mode 100644 gcc/testsuite/g++.dg/warn/huge-val1.C create mode 100644 gcc/testsuite/g++.dg/warn/if-empty-1.C create mode 100644 gcc/testsuite/g++.dg/warn/ignored_typedef.C create mode 100644 gcc/testsuite/g++.dg/warn/implicit-typename1.C create mode 100644 gcc/testsuite/g++.dg/warn/implicit-typename2.C create mode 100644 gcc/testsuite/g++.dg/warn/implicit-typename3.C create mode 100644 gcc/testsuite/g++.dg/warn/incomplete1.C create mode 100644 gcc/testsuite/g++.dg/warn/incomplete2.C create mode 100644 gcc/testsuite/g++.dg/warn/inline1.C create mode 100644 gcc/testsuite/g++.dg/warn/inline2.C create mode 100644 gcc/testsuite/g++.dg/warn/main-2.C create mode 100644 gcc/testsuite/g++.dg/warn/main-3.C create mode 100644 gcc/testsuite/g++.dg/warn/main-4.C create mode 100644 gcc/testsuite/g++.dg/warn/main.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-1.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-2.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-3.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-4.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-5.C create mode 100644 gcc/testsuite/g++.dg/warn/miss-format-6.C create mode 100644 gcc/testsuite/g++.dg/warn/missing-field-init-1.C create mode 100644 gcc/testsuite/g++.dg/warn/missing-field-init-2.C create mode 100644 gcc/testsuite/g++.dg/warn/multiple-overflow-warn-1.C create mode 100644 gcc/testsuite/g++.dg/warn/multiple-overflow-warn-2.C create mode 100644 gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C create mode 100644 gcc/testsuite/g++.dg/warn/new1.C create mode 100644 gcc/testsuite/g++.dg/warn/no-write-strings.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect2.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect4.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect5.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect6.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect7.C create mode 100644 gcc/testsuite/g++.dg/warn/noeffect8.C create mode 100644 gcc/testsuite/g++.dg/warn/nonnull1.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-1.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-2.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-3.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-4.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-5.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-6.C create mode 100644 gcc/testsuite/g++.dg/warn/noreturn-7.C create mode 100644 gcc/testsuite/g++.dg/warn/null4.C create mode 100644 gcc/testsuite/g++.dg/warn/oldcast1.C create mode 100644 gcc/testsuite/g++.dg/warn/overflow-warn-1.C create mode 100644 gcc/testsuite/g++.dg/warn/overflow-warn-3.C create mode 100644 gcc/testsuite/g++.dg/warn/overflow-warn-4.C create mode 100644 gcc/testsuite/g++.dg/warn/overflow-warn-5.C create mode 100644 gcc/testsuite/g++.dg/warn/overflow-warn-6.C create mode 100644 gcc/testsuite/g++.dg/warn/pedantic1.C create mode 100644 gcc/testsuite/g++.dg/warn/pedantic2.C create mode 100644 gcc/testsuite/g++.dg/warn/pmf1.C create mode 100644 gcc/testsuite/g++.dg/warn/pointer-integer-comparison.C create mode 100644 gcc/testsuite/g++.dg/warn/pr11159.C create mode 100644 gcc/testsuite/g++.dg/warn/pr11492.C create mode 100644 gcc/testsuite/g++.dg/warn/pr12242.C create mode 100644 gcc/testsuite/g++.dg/warn/pr13358-2.C create mode 100644 gcc/testsuite/g++.dg/warn/pr13358-3.C create mode 100644 gcc/testsuite/g++.dg/warn/pr13358-4.C create mode 100644 gcc/testsuite/g++.dg/warn/pr13358.C create mode 100644 gcc/testsuite/g++.dg/warn/pr15774-1.C create mode 100644 gcc/testsuite/g++.dg/warn/pr15774-2.C create mode 100644 gcc/testsuite/g++.dg/warn/pr16302.C create mode 100644 gcc/testsuite/g++.dg/warn/pr21983.C create mode 100644 gcc/testsuite/g++.dg/warn/pr23075.C create mode 100644 gcc/testsuite/g++.dg/warn/pr26785.C create mode 100644 gcc/testsuite/g++.dg/warn/pr28943.C create mode 100644 gcc/testsuite/g++.dg/warn/pr30551-2.C create mode 100644 gcc/testsuite/g++.dg/warn/pr30551.C create mode 100644 gcc/testsuite/g++.dg/warn/pr30636.C create mode 100644 gcc/testsuite/g++.dg/warn/pr31246-2.C create mode 100644 gcc/testsuite/g++.dg/warn/pr31246.C create mode 100644 gcc/testsuite/g++.dg/warn/pr33160.C create mode 100644 gcc/testsuite/g++.dg/warn/pr33738.C create mode 100644 gcc/testsuite/g++.dg/warn/pr34985.C create mode 100644 gcc/testsuite/g++.dg/warn/pr35602.C create mode 100644 gcc/testsuite/g++.dg/warn/pr35635.C create mode 100644 gcc/testsuite/g++.dg/warn/pr35711.C create mode 100644 gcc/testsuite/g++.dg/warn/pr36069.C create mode 100644 gcc/testsuite/g++.dg/warn/pr36921.C create mode 100644 gcc/testsuite/g++.dg/warn/pr36954.C create mode 100644 gcc/testsuite/g++.dg/warn/pr36999.C create mode 100644 gcc/testsuite/g++.dg/warn/pr5310.C create mode 100644 gcc/testsuite/g++.dg/warn/pr5645.C create mode 100644 gcc/testsuite/g++.dg/warn/pr8570.C create mode 100644 gcc/testsuite/g++.dg/warn/pr8715.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header1.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header1.h create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header2.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header2.h create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header3.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header3.h create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header4.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header4.h create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header5.C create mode 100644 gcc/testsuite/g++.dg/warn/pragma-system_header5.h create mode 100644 gcc/testsuite/g++.dg/warn/private1.C create mode 100644 gcc/testsuite/g++.dg/warn/register-var-1.C create mode 100644 gcc/testsuite/g++.dg/warn/register-var-2.C create mode 100644 gcc/testsuite/g++.dg/warn/return-reference.C create mode 100644 gcc/testsuite/g++.dg/warn/return-reference2.C create mode 100644 gcc/testsuite/g++.dg/warn/sentinel.C create mode 100644 gcc/testsuite/g++.dg/warn/sequence-pt-1.C create mode 100644 gcc/testsuite/g++.dg/warn/sequence-pt-2.C create mode 100644 gcc/testsuite/g++.dg/warn/sequence-pt-3.C create mode 100644 gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C create mode 100644 gcc/testsuite/g++.dg/warn/skip-1.C create mode 100644 gcc/testsuite/g++.dg/warn/skip-2.C create mode 100644 gcc/testsuite/g++.dg/warn/string1.C create mode 100644 gcc/testsuite/g++.dg/warn/switch1.C create mode 100644 gcc/testsuite/g++.dg/warn/template-1.C create mode 100644 gcc/testsuite/g++.dg/warn/translate-ice-1.C create mode 100644 gcc/testsuite/g++.dg/warn/undefined1.C create mode 100644 gcc/testsuite/g++.dg/warn/unit-1.C create mode 100644 gcc/testsuite/g++.dg/warn/unused-result1-Werror.c create mode 100644 gcc/testsuite/g++.dg/warn/unused-result1.C create mode 100644 gcc/testsuite/g++.dg/warn/var-args1.C create mode 100644 gcc/testsuite/g++.dg/warn/volatile1.C create mode 100644 gcc/testsuite/g++.dg/warn/weak1.C create mode 100644 gcc/testsuite/g++.dg/warn/write-strings-default.C create mode 100644 gcc/testsuite/g++.dg/warn/write-strings.C (limited to 'gcc/testsuite/g++.dg/warn') diff --git a/gcc/testsuite/g++.dg/warn/Wall-write-strings.C b/gcc/testsuite/g++.dg/warn/Wall-write-strings.C new file mode 100644 index 000000000..e380b321b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wall-write-strings.C @@ -0,0 +1,7 @@ +// PR 8586 +// { dg-do compile } +// { dg-options "-Wall" } + +char* foo = "foo"; // { dg-warning "" } +const char* bar = "bar"; + diff --git a/gcc/testsuite/g++.dg/warn/Walways-true-1.C b/gcc/testsuite/g++.dg/warn/Walways-true-1.C new file mode 100644 index 000000000..ae6f9dc83 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Walways-true-1.C @@ -0,0 +1,57 @@ +// Test -Waddress for testing an address against NULL. +// Origin: Ian Lance Taylor + +// { dg-do compile } +// { dg-options "-Waddress" } + +extern int foo (int); + +int i; + +void +bar (int a) +{ + lab: + if (foo) // { dg-warning "always evaluate as" "correct warning" } + foo (0); + if (foo (1)) + ; + if (&i) // { dg-warning "always evaluate as" "correct warning" } + foo (2); + if (i) + foo (3); + if (&a) // { dg-warning "always evaluate as" "correct warning" } + foo (4); + if (a) + foo (5); + if (&&lab) // { dg-warning "always evaluate as" "correct warning" } + foo (6); + if (foo == 0) // { dg-warning "never be NULL" "correct warning" } + foo (7); + if (foo (1) == 0) + foo (8); + if (&i == 0) // { dg-warning "never be NULL" "correct warning" } + foo (9); + if (i == 0) + foo (10); + if (&a == 0) // { dg-warning "never be NULL" "correct warning" } + foo (11); + if (a == 0) + foo (12); + if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } + foo (13); + if (0 == foo) // { dg-warning "never be NULL" "correct warning" } + foo (14); + if (0 == foo (1)) + foo (15); + if (0 == &i) // { dg-warning "never be NULL" "correct warning" } + foo (16); + if (0 == i) + foo (17); + if (0 == &a) // { dg-warning "never be NULL" "correct warning" } + foo (18); + if (0 == a) + foo (19); + if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } + foo (20); +} diff --git a/gcc/testsuite/g++.dg/warn/Walways-true-2.C b/gcc/testsuite/g++.dg/warn/Walways-true-2.C new file mode 100644 index 000000000..f1573470e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Walways-true-2.C @@ -0,0 +1,60 @@ +// Make sure we don't assume that a weak symbol is always non-NULL. +// This is just like Walways-true-1.C, except that it uses a weak +// symbol. +// Origin: Ian Lance Taylor + +// { dg-do compile } +// { dg-options "-Waddress" } +// { dg-require-weak "" } + +extern int foo (int) __attribute__ ((weak)); + +int i __attribute__ ((weak)); + +void +bar (int a) +{ + lab: + if (foo) + foo (0); + if (foo (1)) + ; + if (&i) + foo (2); + if (i) + foo (3); + if (&a) // { dg-warning "always evaluate as" "correct warning" } + foo (4); + if (a) + foo (5); + if (&&lab) // { dg-warning "always evaluate as" "correct warning" } + foo (6); + if (foo == 0) + foo (7); + if (foo (1) == 0) + foo (8); + if (&i == 0) + foo (9); + if (i == 0) + foo (10); + if (&a == 0) // { dg-warning "never be NULL" "correct warning" } + foo (11); + if (a == 0) + foo (12); + if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } + foo (13); + if (0 == foo) + foo (14); + if (0 == foo (1)) + foo (15); + if (0 == &i) + foo (16); + if (0 == i) + foo (17); + if (0 == &a) // { dg-warning "never be NULL" "correct warning" } + foo (18); + if (0 == a) + foo (19); + if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } + foo (20); +} diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-2.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-2.C new file mode 100644 index 000000000..796483e0e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-2.C @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* Test that -Warray-bounds is enabled by -Wall */ +/* { dg-options "-O2 -Wall" } */ + +int a[10]; + +int* f(void) { + + a[-1] = 0; /* { dg-warning "array subscript" } */ + + return a; +} + diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C new file mode 100644 index 000000000..a85857179 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-3.C @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall" } */ + +extern void function(void * x); + +struct A { + long x; + char d[0]; +}; + + +void test(A * a) { + function((char *)a - 4); /* { dg-bogus "below array bounds" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-4.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-4.C new file mode 100644 index 000000000..319038a73 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-4.C @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-O2 -Warray-bounds" } + +class String +{ +public: + virtual unsigned long length() const = 0; + virtual char get(unsigned long index) const = 0; + virtual void set(unsigned long index, char value) = 0; + virtual char& operator[] (unsigned long value) = 0; + virtual ~String() {}; +}; + +template class FixedString : public String +{ +private: + char contents[size]; + +public: + virtual unsigned long length() const { return size; } + virtual char get(unsigned long index) const { return contents[index]; } + virtual void set(unsigned long index, char value) { contents[index] = value; } + virtual char& operator[] (unsigned long index) { return contents[index]; } + + FixedString() { contents[0] = '\0'; } // { dg-warning "above array bounds" } +}; + +void print_length (const String& string); + +int main() +{ + const FixedString<0> empty; + + print_length(empty); + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C b/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C new file mode 100644 index 000000000..06d776a40 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds-5.C @@ -0,0 +1,24 @@ +// { dg-do compile } +// { dg-options "-O2 -Warray-bounds" } + +void f(); + +int c[3]; +int result; + +struct Vector { + static int get(int i) { + if (i >= 3) + f(); + return c[i]; + } +}; + +void g() +{ + for (int i = 0; i < 3; ++i) { + const int index = i % 3; + result = Vector::get(index) + Vector::get(index); + } +} + diff --git a/gcc/testsuite/g++.dg/warn/Warray-bounds.C b/gcc/testsuite/g++.dg/warn/Warray-bounds.C new file mode 100644 index 000000000..61c7c5d8e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Warray-bounds.C @@ -0,0 +1,92 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds" } */ + +int a[10]; + +extern "C" __SIZE_TYPE__ strlen(const char *s); + +static inline int n(void) { + return strlen("12345"); +} + +void g(int *p); +void h(int p); + +int* f(void) { + int b[10]; + int i; + struct { + int c[10]; + } c; + + a[-1] = 0; /* { dg-warning "array subscript" } */ + a[ 0] = 0; + a[ 1] = 0; + + + a[ 9] = 0; + a[10] = 0; /* { dg-warning "array subscript" } */ + a[11] = 0; /* { dg-warning "array subscript" } */ + a[2 * n() - 11] = 1; /* { dg-warning "array subscript" } */ + a[2 * n() - 10] = 1; + a[2 * n() - 1] = 1; + a[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */ + + b[-1] = 0; /* { dg-warning "array subscript" } */ + b[ 0] = 0; + b[ 1] = 0; + b[ 9] = 0; + b[10] = 0; /* { dg-warning "array subscript" } */ + b[11] = 0; /* { dg-warning "array subscript" } */ + b[2 * n() - 11] = 1; /* { dg-warning "array subscript" } */ + b[2 * n() - 10] = 1; + b[2 * n() - 1] = 1; + b[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */ + + c.c[-1] = 0; /* { dg-warning "array subscript" } */ + c.c[ 0] = 0; + c.c[ 1] = 0; + c.c[ 9] = 0; + c.c[10] = 0; /* { dg-warning "array subscript" } */ + c.c[11] = 0; /* { dg-warning "array subscript" } */ + c.c[2 * n() - 11] = 1; /* { dg-warning "array subscript" } */ + c.c[2 * n() - 10] = 1; + c.c[2 * n() - 1] = 1; + c.c[2 * n() - 0] = 1; /* { dg-warning "array subscript" } */ + + g(&a[8]); + g(&a[9]); + g(&a[10]); + g(&a[11]); /* { dg-warning "array subscript" } */ + g(&a[-30]+10); /* { dg-warning "array subscript" } */ + g(&a[-30]+30); + + g(&b[10]); + g(&c.c[10]); + g(&a[11]); /* { dg-warning "array subscript" } */ + g(&b[11]); /* { dg-warning "array subscript" } */ + g(&c.c[11]); /* { dg-warning "array subscript" } */ + + g(&a[0]); + g(&b[0]); + g(&c.c[0]); + + g(&a[-1]); /* { dg-warning "array subscript" } */ + g(&b[-1]); /* { dg-warning "array subscript" } */ + h(sizeof a[-1]); + h(sizeof a[10]); + h(sizeof b[-1]); + h(sizeof b[10]); + h(sizeof c.c[-1]); + h(sizeof c.c[10]); + + if (10 < 10) + a[10] = 0; + if (10 < 10) + b[10] = 0; + if (-1 >= 0) + c.c[-1] = 0; + + return a; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wbraces1.C b/gcc/testsuite/g++.dg/warn/Wbraces1.C new file mode 100644 index 000000000..0efce7be3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wbraces1.C @@ -0,0 +1,3 @@ +// PR c++/19755 +// { dg-options "-Wmissing-braces" } +int a[2][2] = { 0, 1 , 2, 3 }; // { dg-warning "" } diff --git a/gcc/testsuite/g++.dg/warn/Wbraces2.C b/gcc/testsuite/g++.dg/warn/Wbraces2.C new file mode 100644 index 000000000..6d54ede9b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wbraces2.C @@ -0,0 +1,15 @@ +// PR c++/20175 +// { dg-options "-Wmissing-braces" } +int a[2][2] = { 0, 1, 2, 3 }; // { dg-warning "missing braces" } +int b[2][2] = { { 0, 1 }, { 2, 3 } }; +int c[2][2] = { { { 0 }, 1 }, { 2, 3 } }; // { dg-error "braces around scalar" } +struct S { char s[6]; int i; }; +S d = { "hello", 1 }; +S e = { { "hello" }, 1 }; +S f = { { { "hello" } }, 1 }; // { dg-error "braces around scalar" } +S g = { 'h', 'e', 'l', 'l', 'o', '\0', 1 }; // { dg-warning "missing braces" } +struct T { wchar_t s[6]; int i; }; +T i = { L"hello", 1 }; +T j = { { L"hello" }, 1 }; +T k = { { { L"hello" } }, 1 }; // { dg-error "braces around scalar" } +T l = { L'h', L'e', L'l', L'l', L'o', L'\0', 1 };// { dg-warning "missing braces" } diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual1.C b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C new file mode 100644 index 000000000..e6ad4f6a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C @@ -0,0 +1,7 @@ +// PR c++/24667 +// { dg-options "-Wcast-qual" } + +int main(int, char**) { + const int foo[2] = {1,1}; + ((int*)foo)[0] = 0; // { dg-warning "cast" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual2.C b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C new file mode 100644 index 000000000..88fdcfb38 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C @@ -0,0 +1,167 @@ +/* { dg-do compile } */ +/* { dg-options "-Wcast-qual" } */ + +/* The files gcc.dg/cast-qual-3.c and g++.dg/warn/Wcast-qual2.c are + duals. they are intended to show that gcc -Wcast-qual and g++ + -Wcast-qual emit warnings in the same cases. If you change this + file, please also change the other one. */ + +void +f1 (void *bar) +{ + const void *p1 = (const void *) bar; + const char *p2 = (const char *) bar; + const void **p3 = (const void **) bar; + const char **p4 = (const char **) bar; + const void * const *p5 = (const void * const *) bar; + const char * const *p6 = (const char * const *) bar; + void * const *p7 = (void * const *) bar; + char * const *p8 = (char * const *) bar; + const void ***p9 = (const void ***) bar; + const char ***p10 = (const char ***) bar; + void * const **p11 = (void * const **) bar; + char * const **p12 = (char * const **) bar; + void ** const *p13 = (void ** const *) bar; + char ** const *p14 = (char ** const *) bar; + const void * const **p15 = (const void * const **) bar; + const char * const **p16 = (const char * const **) bar; + const void ** const *p17 = (const void ** const *) bar; + const char ** const *p18 = (const char ** const *) bar; + void * const * const * p19 = (void * const * const *) bar; + char * const * const * p20 = (char * const * const *) bar; + const void * const * const *p21 = (const void * const * const *) bar; + const char * const * const *p22 = (const char * const * const *) bar; +} + +void +f2 (void **bar) +{ + const void *p1 = (const void *) bar; + const char *p2 = (const char *) bar; + const void **p3 = (const void **) bar; /* { dg-warning "cast" } */ + const char **p4 = (const char **) bar; + const void * const *p5 = (const void * const *) bar; + const char * const *p6 = (const char * const *) bar; + void * const *p7 = (void * const *) bar; + char * const *p8 = (char * const *) bar; + const void ***p9 = (const void ***) bar; + const char ***p10 = (const char ***) bar; + void * const **p11 = (void * const **) bar; + char * const **p12 = (char * const **) bar; + void ** const *p13 = (void ** const *) bar; + char ** const *p14 = (char ** const *) bar; + const void * const **p15 = (const void * const **) bar; + const char * const **p16 = (const char * const **) bar; + const void ** const *p17 = (const void ** const *) bar; + const char ** const *p18 = (const char ** const *) bar; + void * const * const * p19 = (void * const * const *) bar; + char * const * const * p20 = (char * const * const *) bar; + const void * const * const *p21 = (const void * const * const *) bar; + const char * const * const *p22 = (const char * const * const *) bar; +} + +void +f3 (void ***bar) +{ + const void *p1 = (const void *) bar; + const char *p2 = (const char *) bar; + const void **p3 = (const void **) bar; + const char **p4 = (const char **) bar; + const void * const *p5 = (const void * const *) bar; + const char * const *p6 = (const char * const *) bar; + void * const *p7 = (void * const *) bar; + char * const *p8 = (char * const *) bar; + const void ***p9 = (const void ***) bar; /* { dg-warning "cast" } */ + const char ***p10 = (const char ***) bar; + void * const **p11 = (void * const **) bar; /* { dg-warning "cast" } */ + char * const **p12 = (char * const **) bar; + void ** const *p13 = (void ** const *) bar; + char ** const *p14 = (char ** const *) bar; + const void * const **p15 = (const void * const **) bar; /* { dg-warning "cast" } */ + const char * const **p16 = (const char * const **) bar; + const void ** const *p17 = (const void ** const *) bar; /* { dg-warning "cast" } */ + const char ** const *p18 = (const char ** const *) bar; + void * const * const * p19 = (void * const * const *) bar; + char * const * const * p20 = (char * const * const *) bar; + const void * const * const *p21 = (const void * const * const *) bar; + const char * const * const *p22 = (const char * const * const *) bar; +} + +void +f4 (void * const **bar) +{ + const void ***p9 = (const void ***) bar; /* { dg-warning "cast" } */ + void * const **p11 = (void * const **) bar; + void ** const *p13 = (void ** const *) bar; /* { dg-warning "cast" } */ + const void * const **p15 = (const void * const **) bar; /* { dg-warning "cast" } */ + const void ** const *p17 = (const void ** const *) bar; /* { dg-warning "cast" } */ + void * const * const * p19 = (void * const * const *) bar; + const void * const * const *p21 = (const void * const * const *) bar; +} + +void +f5 (char ***bar) +{ + volatile const char ***p9 = (volatile const char ***) bar; /* { dg-warning "cast" } */ + volatile char * const **p11 = (volatile char * const **) bar; /* { dg-warning "cast" } */ + volatile char ** const *p13 = (volatile char ** const *) bar; /* { dg-warning "cast" } */ + volatile const char * const **p15 = (volatile const char * const **) bar; /* { dg-warning "cast" } */ + volatile const char ** const *p17 = (volatile const char ** const *) bar; /* { dg-warning "cast" } */ + volatile char * const * const * p19 = (volatile char * const * const *) bar; + volatile const char * const * const *p21 = (volatile const char * const * const *) bar; +} + +void +f6 (char ***bar) +{ + const char * volatile **p9 = (const char * volatile **) bar; /* { dg-warning "cast" } */ + char * volatile const **p11 = (char * volatile const **) bar; /* { dg-warning "cast" } */ + char * volatile * const *p13 = (char * volatile * const *) bar; + const char * volatile const **p15 = (const char * volatile const **) bar; /* { dg-warning "cast" } */ + const char * volatile * const *p17 = (const char * volatile * const *) bar; /* { dg-warning "cast" } */ + char * volatile const * const * p19 = (char * volatile const * const *) bar; + const char * volatile const * const *p21 = (const char * volatile const * const *) bar; +} + +void +f7 (char ***bar) +{ + const char ** volatile *p9 = (const char ** volatile *) bar; /* { dg-warning "cast" } */ + char * const * volatile *p11 = (char * const * volatile *) bar; /* { dg-warning "cast" } */ + char ** volatile const *p13 = (char ** volatile const *) bar; + const char * const * volatile *p15 = (const char * const * volatile *) bar; /* { dg-warning "cast" } */ + const char ** volatile const *p17 = (const char ** volatile const *) bar; /* { dg-warning "cast" } */ + char * const * volatile const * p19 = (char * const * volatile const *) bar; + const char * const * volatile const *p21 = (const char * const * volatile const *) bar; +} + +typedef int (intfn) (int); +typedef intfn *pintfn; +typedef const intfn *constfn; + +void +f8 (constfn ***bar) +{ + const constfn *p1 = (const constfn *) bar; + const pintfn *p2 = (const pintfn *) bar; + const constfn **p3 = (const constfn **) bar; + const pintfn **p4 = (const pintfn **) bar; + const constfn * const *p5 = (const constfn * const *) bar; + const pintfn * const *p6 = (const pintfn * const *) bar; + constfn * const *p7 = (constfn * const *) bar; + pintfn * const *p8 = (pintfn * const *) bar; + const constfn ***p9 = (const constfn ***) bar; /* { dg-warning "cast" } */ + const pintfn ***p10 = (const pintfn ***) bar; /* { dg-warning "cast" } */ + constfn * const **p11 = (constfn * const **) bar; /* { dg-warning "cast" } */ + pintfn * const **p12 = (pintfn * const **) bar; /* { dg-warning "cast" } */ + constfn ** const *p13 = (constfn ** const *) bar; + pintfn ** const *p14 = (pintfn ** const *) bar; + const constfn * const **p15 = (const constfn * const **) bar; /* { dg-warning "cast" } */ + const pintfn * const **p16 = (const pintfn * const **) bar; /* { dg-warning "cast" } */ + const constfn ** const *p17 = (const constfn ** const *) bar; /* { dg-warning "cast" } */ + const pintfn ** const *p18 = (const pintfn ** const *) bar; /* { dg-warning "cast" } */ + constfn * const * const * p19 = (constfn * const * const *) bar; + pintfn * const * const * p20 = (pintfn * const * const *) bar; + const constfn * const * const *p21 = (const constfn * const * const *) bar; + const pintfn * const * const *p22 = (const pintfn * const * const *) bar; +} diff --git a/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C b/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C new file mode 100644 index 000000000..2170cb206 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wchar-subscripts-2.C @@ -0,0 +1,15 @@ +/* PR c++/16307 */ +// { dg-do compile } +// { dg-options "-Wchar-subscripts" } + +extern volatile char bla; + +char foo (const char *s) +{ + return s [bla]; // { dg-warning "array subscript" } +} + +int main () +{ + foo ("\x80"); +} diff --git a/gcc/testsuite/g++.dg/warn/Wchar-subscripts.C b/gcc/testsuite/g++.dg/warn/Wchar-subscripts.C new file mode 100644 index 000000000..bc38585d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wchar-subscripts.C @@ -0,0 +1,12 @@ +/* Copyright (C) 2005 Free Software Foundation. + + by Gabriel Dos Reis */ + +// { dg-do compile } +// { dg-options "-Wchar-subscripts" } + +int main() +{ + int ary[256] = { 0 }; + return ary['a']; +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-integer.C b/gcc/testsuite/g++.dg/warn/Wconversion-integer.C new file mode 100644 index 000000000..42d9cb000 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-integer.C @@ -0,0 +1,94 @@ +/* Test for diagnostics for implicit conversions between integer types + C++ equivalent of gcc/testsuite/gcc.dg/Wconversion-integer.c */ + +// { dg-do compile } +// { dg-options "-fsigned-char -Wconversion" } + +#include + +void fsc (signed char sc); +void fuc (unsigned char uc); +unsigned fui (unsigned int ui); +void fsi (signed int ui); + +void h (int x) +{ + unsigned int ui = 3; + int si = 3; + unsigned char uc = 3; + signed char sc = 3; + + uc = ui; /* { dg-warning "conversion" } */ + uc = si; /* { dg-warning "conversion" } */ + sc = ui; /* { dg-warning "conversion" } */ + sc = si; /* { dg-warning "conversion" } */ + fuc (ui); /* { dg-warning "conversion" } */ + fuc (si); /* { dg-warning "conversion" } */ + fsc (ui); /* { dg-warning "conversion" } */ + fsc (si); /* { dg-warning "conversion" } */ + + fsi (si); + fui (ui); + fsi (uc); + si = uc; + fui (uc); + ui = uc; + fui ('A'); + ui = 'A'; + fsi ('A'); + si = 'A'; + fuc ('A'); + uc = 'A'; + + uc = x ? 1U : -1; /* { dg-warning "conversion" } */ + uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */ + uc = x ? 1 : -1; /* Warned by -Wsign-conversion. */ + uc = x ? SCHAR_MIN : 1; /* Warned by -Wsign-conversion. */ + ui = x ? 1U : -1; /* Warned by -Wsign-conversion. */ + ui = x ? INT_MIN : 1U; /* Warned by -Wsign-conversion. */ + ui = ui ? SCHAR_MIN : 1U; /* Warned by -Wsign-conversion. */ + ui = 1U * -1; /* Warned by -Wsign-conversion. */ + ui = ui + INT_MIN; /* Warned by -Wsign-conversion. */ + ui = x ? 1 : -1; /* Warned by -Wsign-conversion. */ + ui = ui ? SCHAR_MIN : 1; /* Warned by -Wsign-conversion. */ + + fuc (-1); /* Warned by -Wsign-conversion. */ + uc = -1; /* Warned by -Wsign-conversion. */ + fui (-1); /* Warned by -Wsign-conversion. */ + ui = -1; /* Warned by -Wsign-conversion. */ + fuc ('\xa0'); /* Warned by -Wsign-conversion. */ + uc = '\xa0'; /* Warned by -Wsign-conversion. */ + fui ('\xa0'); /* Warned by -Wsign-conversion. */ + ui = '\xa0'; /* Warned by -Wsign-conversion. */ + fsi (0x80000000); /* Warned by -Wsign-conversion. */ + si = 0x80000000; /* Warned by -Wsign-conversion. */ + + + fsi (UINT_MAX - 1); /* Warned by -Wsign-conversion. */ + si = UINT_MAX - 1; /* Warned by -Wsign-conversion. */ + fsi (UINT_MAX - 1U); /* Warned by -Wsign-conversion. */ + si = UINT_MAX - 1U; /* Warned by -Wsign-conversion. */ + fsi (UINT_MAX/3U); + si = UINT_MAX/3U; + fsi (UINT_MAX/3); + si = UINT_MAX/3; + fui (UINT_MAX - 1); + ui = UINT_MAX - 1; + + uc = (unsigned char) -1; + ui = -1 * (1 * -1); + ui = (unsigned) -1; + + fsc (uc); /* Warned by -Wsign-conversion. */ + sc = uc; /* Warned by -Wsign-conversion. */ + fuc (sc); /* Warned by -Wsign-conversion. */ + uc = sc; /* Warned by -Wsign-conversion. */ + fsi (ui); /* Warned by -Wsign-conversion. */ + si = ui; /* Warned by -Wsign-conversion. */ + fui (si); /* Warned by -Wsign-conversion. */ + ui = si; /* Warned by -Wsign-conversion. */ + fui (sc); /* Warned by -Wsign-conversion. */ + ui = sc; /* Warned by -Wsign-conversion. */ +} + +unsigned fui (unsigned a) { return a + -1; } /* Warned by -Wsign-conversion. */ diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C b/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C new file mode 100644 index 000000000..c3050f612 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C @@ -0,0 +1,49 @@ +// { dg-do link } +// { dg-options "" } + +#include + +void g(int) {} +void g(long) {} +void g(long long) {} +extern void g(void*); + +template +void h() {} + +void k(int) {} + +template +void l(T); + +template <> +void l(int) {} + +template <> +void l(long) {} + +template <> +void l(long long) {} + +int main() +{ + int i = NULL; // { dg-warning "" } converting NULL to non-pointer type + float z = NULL; // { dg-warning "" } converting NULL to non-pointer type + int a[2]; + + i != NULL; // { dg-warning "" } NULL used in arithmetic + NULL != z; // { dg-warning "" } NULL used in arithmetic + k != NULL; // No warning: decay conversion + NULL != a; // Likewise. + -NULL; // { dg-warning "" } converting NULL to non-pointer type + +NULL; // { dg-warning "" } converting NULL to non-pointer type + ~NULL; // { dg-warning "" } converting NULL to non-pointer type + a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type + i = NULL; // { dg-warning "" } converting NULL to non-pointer type + z = NULL; // { dg-warning "" } converting NULL to non-pointer type + k(NULL); // { dg-warning "" } converting NULL to int + g(NULL); // { dg-warning "" } converting NULL to int + h(); // No warning: NULL bound to integer template parameter + l(NULL); // { dg-warning "" } converting NULL to int + NULL && NULL; // No warning: converting NULL to bool is OK +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null.C b/gcc/testsuite/g++.dg/warn/Wconversion-null.C new file mode 100644 index 000000000..e2ca13e51 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-null.C @@ -0,0 +1,49 @@ +// { dg-do link } +// { dg-options "-Wconversion -Wno-conversion-null -Wno-pointer-arith" } + +#include + +void g(int) {} +void g(long) {} +void g(long long) {} +extern void g(void*); + +template +void h() {} + +void k(int) {} + +template +void l(T); + +template <> +void l(int) {} + +template <> +void l(long) {} + +template <> +void l(long long) {} + +int main() +{ + int i = NULL; // converting NULL to non-pointer type + float z = NULL; // converting NULL to non-pointer type + int a[2]; + + i != NULL; // NULL used in arithmetic + NULL != z; // NULL used in arithmetic + k != NULL; // No warning: decay conversion + NULL != a; // Likewise. + -NULL; // converting NULL to non-pointer type + +NULL; // converting NULL to non-pointer type + ~NULL; // converting NULL to non-pointer type + a[NULL] = 3; // converting NULL to non-pointer-type + i = NULL; // converting NULL to non-pointer type + z = NULL; // converting NULL to non-pointer type + k(NULL); // converting NULL to int + g(NULL); // converting NULL to int + h(); // No warning: NULL bound to integer template parameter + l(NULL); // converting NULL to int + NULL && NULL; // No warning: converting NULL to bool is OK +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C b/gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C new file mode 100644 index 000000000..43df8f902 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-pr34389.C @@ -0,0 +1,54 @@ +/* PR 34389 */ +/* { dg-do compile } */ +/* { dg-options "-Wconversion -Wsign-conversion" } */ +/* { dg-require-effective-target int32plus } */ +short mask1(short x) +{ + short y = 0x7fff; + return x & y; /* { dg-bogus "conversion" "bogus warning" } */ +} + +short mask2(short ssx) +{ + short ssy; + short ssz; + + ssz = ((int)ssx) & 0x7fff; + ssy = ((int)ssx) | 0x7fff; + ssz = ((int)ssx) ^ 0x7fff; + return ssx & 0x7fff; +} + +short mask3(int si, unsigned int ui) +{ + short ss; + unsigned short us; + + ss = si & 0x7fff; + ss = si & 0xAAAA; /* { dg-warning "conversion" } */ + ss = ui & 0x7fff; + ss = ui & 0xAAAA; /* { dg-warning "conversion" } */ + + us = si & 0x7fff; + us = si & 0xAAAA; /* { dg-warning "conversion" } */ + us = ui & 0x7fff; + us = ui & 0xAAAA; /* 0xAAAA is zero-extended, thus it masks the + upper bits of 'ui' making it fit in 'us'. */ + + return ss; +} + +short mask4(int x, int y) +{ + return x & y; /* { dg-warning "conversion" } */ +} + +short mask5(int x) +{ + return x & -1; /* { dg-warning "conversion" } */ +} + +short mask6(short x) +{ + return x & -1; +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C b/gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C new file mode 100644 index 000000000..282ac13da --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-real-integer.C @@ -0,0 +1,112 @@ +/* Test for diagnostics for Wconversion between floating-point and + integers. C++ equivalent of + gcc/testsuite/gcc.dg/Wconversion-real-integer.c */ + +/* { dg-do compile } +/* { dg-options "-Wconversion" } */ +/* { dg-require-effective-target int32plus } */ +#include + +void fsi (signed int x); +void fui (unsigned int x); +void ffloat (float x); +void fdouble (double x); + +float vfloat; +double vdouble; + +void h (void) +{ + unsigned int ui = 3; + int si = 3; + unsigned char uc = 3; + signed char sc = 3; + float f = 3; + double d = 3; + + fsi (3.1f); /* { dg-warning "conversion" } */ + si = 3.1f; /* { dg-warning "conversion" } */ + fsi (3.1); /* { dg-warning "conversion" } */ + si = 3.1; /* { dg-warning "conversion" } */ + fsi (d); /* { dg-warning "conversion" } */ + si = d; /* { dg-warning "conversion" } */ + fui (-1.0); /* { dg-warning "overflow" } */ + ui = -1.0; /* { dg-warning "overflow" } */ + ffloat (INT_MAX); /* { dg-warning "conversion" } */ + vfloat = INT_MAX; /* { dg-warning "conversion" } */ + ffloat (16777217); /* { dg-warning "conversion" } */ + vfloat = 16777217; /* { dg-warning "conversion" } */ + ffloat (si); /* { dg-warning "conversion" } */ + vfloat = si; /* { dg-warning "conversion" } */ + ffloat (ui); /* { dg-warning "conversion" } */ + vfloat = ui; /* { dg-warning "conversion" } */ + + fsi (3); + si = 3; + fsi (3.0f); + si = 3.0f; + fsi (3.0); + si = 3.0; + fsi (16777217.0f); + si = 16777217.0f; + fsi ((int) 3.1); + si = (int) 3.1; + ffloat (3U); + vfloat = 3U; + ffloat (3); + vfloat = 3; + ffloat (INT_MIN); + vfloat = INT_MIN; + ffloat (uc); + vfloat = uc; + ffloat (sc); + vfloat = sc; + + fdouble (UINT_MAX); + vdouble = UINT_MAX; + fdouble (ui); + vdouble = ui; + fdouble (si); + vdouble = si; +} + + +void fss (signed short x); +void fus (unsigned short x); +void fsc (signed char x); +void fuc (unsigned char x); + +void h2 (void) +{ + unsigned short int us; + short int ss; + unsigned char uc; + signed char sc; + + fss (4294967294.0); /* { dg-warning "conversion" } */ + ss = 4294967294.0; /* { dg-warning "conversion" } */ + fss (-4294967294.0); /* { dg-warning "conversion" } */ + ss = -4294967294.0; /* { dg-warning "conversion" } */ + fus (4294967294.0); /* { dg-warning "conversion" } */ + us = 4294967294.0; /* { dg-warning "conversion" } */ + fus (-4294967294.0); /* { dg-warning "conversion" } */ + us = -4294967294.0; /* { dg-warning "conversion" } */ + + fsc (500.0); /* { dg-warning "conversion" } */ + sc = 500.0; /* { dg-warning "conversion" } */ + fsc (-500.0); /* { dg-warning "conversion" } */ + sc = -500.0; /* { dg-warning "conversion" } */ + fuc (500.0); /* { dg-warning "conversion" } */ + uc = 500.0; /* { dg-warning "conversion" } */ + fuc (-500.0); /* { dg-warning "conversion" } */ + uc = -500.0; /* { dg-warning "conversion" } */ + + fss (500.0); + ss = 500.0; + fss (-500.0); + ss = -500.0; + fus (500.0); + us = 500.0; + fus (-500.0); /* { dg-warning "conversion" } */ + us = -500.0; /* { dg-warning "conversion" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-real.C b/gcc/testsuite/g++.dg/warn/Wconversion-real.C new file mode 100644 index 000000000..e69de29bb diff --git a/gcc/testsuite/g++.dg/warn/Wconversion1.C b/gcc/testsuite/g++.dg/warn/Wconversion1.C new file mode 100644 index 000000000..48e319ad6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion1.C @@ -0,0 +1,12 @@ +// { dg-options "-fsigned-char -Wsign-conversion" } + +char c1 = 1024; // { dg-warning "overflow" } +char c2 = char(1024); +char c3 = (char) 1024; +char c4 = static_cast(1024); + +unsigned char uc1 = -129; // { dg-warning "unsigned" } + +bool b1 = -3; + +int i1 = 0x80000000; // { dg-warning "conversion" } diff --git a/gcc/testsuite/g++.dg/warn/Wconversion2.C b/gcc/testsuite/g++.dg/warn/Wconversion2.C new file mode 100644 index 000000000..226dd852b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion2.C @@ -0,0 +1,3 @@ +// { dg-options "-Wconversion-null" } +void foo(const char *); +void bar() { foo(false); } // { dg-warning "pointer type for argument" } diff --git a/gcc/testsuite/g++.dg/warn/Wconversion3.C b/gcc/testsuite/g++.dg/warn/Wconversion3.C new file mode 100644 index 000000000..24202b7d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion3.C @@ -0,0 +1,35 @@ +// PR c++/34198 +// { dg-do compile } +// { dg-options "-O2 -Wconversion -Wsign-conversion" } + +signed char sc; +unsigned char uc; +short int ss; +unsigned short int us; +int si; +unsigned int ui; + +void test1 (void) +{ + int a = uc & 0xff; + int b = sc & 0x7f; + int c = 0xff & uc; + int d = 0x7f & sc; + int e = uc & sc; + unsigned char f = (int) uc; + signed char g = (int) sc; + unsigned char h = (unsigned int) (short int) uc; + signed char i = (int) (unsigned short int) sc; // { dg-warning "may alter its value" } + unsigned char j = (unsigned int) (short int) us; // { dg-warning "may alter its value" } + signed char k = (int) (unsigned short int) ss; // { dg-warning "may alter its value" } +} + +void test2 (void) +{ + signed char a = (unsigned char) sc; // { dg-warning "may change the sign" } + unsigned char b = (signed char) uc; // { dg-warning "may change the sign" } + signed char c = (int) (unsigned char) sc; // { dg-warning "may change the sign" } + unsigned char d = (int) (signed char) uc; // { dg-warning "may change the sign" } + int e = (unsigned int) si; // { dg-warning "may change the sign" } + unsigned int f = (int) ui; // { dg-warning "may change the sign" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wctor-dtor.C b/gcc/testsuite/g++.dg/warn/Wctor-dtor.C new file mode 100644 index 000000000..15efb6b57 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wctor-dtor.C @@ -0,0 +1,13 @@ +// PR c++/21347 +// { dg-options "-Wctor-dtor-privacy" } + +class A { +public: + int x; + int getX() { return x; } // comment out to avoid warning +}; + +int foo() { + A a; // accepted: clearly the ctor is not private + return a.x; +} diff --git a/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C new file mode 100644 index 000000000..7dc77667c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdiv-by-zero.C @@ -0,0 +1,7 @@ +// test that division by zero warnings are enabled by default +int breakme() +{ + int x = 0; + x /= 0; // { dg-warning "division by" } + return x; +} diff --git a/gcc/testsuite/g++.dg/warn/Wdouble-promotion.C b/gcc/testsuite/g++.dg/warn/Wdouble-promotion.C new file mode 100644 index 000000000..9b4044f77 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdouble-promotion.C @@ -0,0 +1,99 @@ +/* { dg-do compile } */ +/* { dg-options "-Wdouble-promotion" } */ + +#include + +/* Some targets do not provide so we define I ourselves. */ +#define I 1.0iF +#define ID ((_Complex double)I) + +float f; +double d; +int i; +long double ld; +_Complex float cf; +_Complex double cd; +_Complex long double cld; +size_t s; + +extern void varargs_fn (int, ...); +extern void double_fn (double); +extern float float_fn (void); + +void +usual_arithmetic_conversions(void) +{ + float local_f; + _Complex float local_cf; + + /* Values of type "float" are implicitly converted to "double" or + "long double" due to use in arithmetic with "double" or "long + double" operands. */ + local_f = f + 1.0; /* { dg-warning "implicit" } */ + local_f = f - d; /* { dg-warning "implicit" } */ + local_f = 1.0f * 1.0; /* { dg-warning "implicit" } */ + local_f = 1.0f / d; /* { dg-warning "implicit" } */ + + local_cf = cf + 1.0; /* { dg-warning "implicit" } */ + local_cf = cf - d; /* { dg-warning "implicit" } */ + local_cf = cf + 1.0 * ID; /* { dg-warning "implicit" } */ + local_cf = cf - cd; /* { dg-warning "implicit" } */ + + local_f = i ? f : d; /* { dg-warning "implicit" } */ + i = f == d; /* { dg-warning "implicit" } */ + i = d != f; /* { dg-warning "implicit" } */ +} + +void +default_argument_promotion (void) +{ + /* Because "f" is part of the variable argument list, it is promoted + to "double". */ + varargs_fn (1, f); /* { dg-warning "implicit" } */ +} + +/* There is no warning when an explicit cast is used to perform the + conversion. */ + +void +casts (void) +{ + float local_f; + _Complex float local_cf; + + local_f = (double)f + 1.0; /* { dg-bogus "implicit" } */ + local_f = (double)f - d; /* { dg-bogus "implicit" } */ + local_f = (double)1.0f + 1.0; /* { dg-bogus "implicit" } */ + local_f = (double)1.0f - d; /* { dg-bogus "implicit" } */ + + local_cf = (_Complex double)cf + 1.0; /* { dg-bogus "implicit" } */ + local_cf = (_Complex double)cf - d; /* { dg-bogus "implicit" } */ + local_cf = (_Complex double)cf + 1.0 * ID; /* { dg-bogus "implicit" } */ + local_cf = (_Complex double)cf - cd; /* { dg-bogus "implicit" } */ + + local_f = i ? (double)f : d; /* { dg-bogus "implicit" } */ + i = (double)f == d; /* { dg-bogus "implicit" } */ + i = d != (double)f; /* { dg-bogus "implicit" } */ +} + +/* There is no warning on conversions that occur in assignment (and + assignment-like) contexts. */ + +void +assignments (void) +{ + d = f; /* { dg-bogus "implicit" } */ + double_fn (f); /* { dg-bogus "implicit" } */ + d = float_fn (); /* { dg-bogus "implicit" } */ +} + +/* There is no warning in non-evaluated contexts. */ + +void +non_evaluated (void) +{ + s = sizeof (f + 1.0); /* { dg-bogus "implicit" } */ + s = __alignof__ (f + 1.0); /* { dg-bogus "implicit" } */ + d = (__typeof__(f + 1.0))f; /* { dg-bogus "implicit" } */ + s = sizeof (i ? f : d); /* { dg-bogus "implicit" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wdtor1.C b/gcc/testsuite/g++.dg/warn/Wdtor1.C new file mode 100644 index 000000000..34c8a7edc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdtor1.C @@ -0,0 +1,22 @@ +// PR c++/20145 +// { dg-options "-Wnon-virtual-dtor" } +# 1 "t.cc" +# 1 "" +# 1 "" +# 1 "t.cc" +# 1 "include/t.h" 1 3 4 +// Declare the template with explicit C++ linkage in case system +// headers have implicit C linkage. +extern "C++" { +template class t +{ + virtual void f(); +}; +} +# 2 "t.cc" 2 + +void f(void) +{ + t<1> h; +} + diff --git a/gcc/testsuite/g++.dg/warn/Weff1.C b/gcc/testsuite/g++.dg/warn/Weff1.C new file mode 100644 index 000000000..a00dc29bf --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Weff1.C @@ -0,0 +1,5 @@ +// { dg-options "-Weffc++" } + +struct S {}; +/* Base classes should have virtual destructors. */ +struct T : public S {}; // { dg-warning "" } diff --git a/gcc/testsuite/g++.dg/warn/Wenum-compare-no.C b/gcc/testsuite/g++.dg/warn/Wenum-compare-no.C new file mode 100644 index 000000000..7dc27d3fe --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wenum-compare-no.C @@ -0,0 +1,10 @@ +/* Test disabling -Wenum-compare (on by default). See PR27975. */ +/* { dg-do compile } */ +/* { dg-options "-Wno-enum-compare" } */ +enum E1 { a }; +enum E2 { b }; + +int foo (E1 e1, E2 e2) +{ + return e1 == e2; /* { dg-bogus "comparison between" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wenum-compare.C b/gcc/testsuite/g++.dg/warn/Wenum-compare.C new file mode 100644 index 000000000..f60080039 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wenum-compare.C @@ -0,0 +1,10 @@ +/* Test that we get the -Wenum-compare by default. See PR27975. */ +/* { dg-do compile } */ +/* { dg-options "" } */ +enum E1 { a }; +enum E2 { b }; + +int foo (E1 e1, E2 e2) +{ + return e1 == e2; /* { dg-warning "comparison between" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wextra-1.C b/gcc/testsuite/g++.dg/warn/Wextra-1.C new file mode 100644 index 000000000..c75a6b087 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wextra-1.C @@ -0,0 +1,12 @@ +// { dg-options "-Wextra" } + +struct T { + // If the implicitly-declared default constructor for "T" is + // required, an error will be issued because "i" cannot be + // initialized. And, this class is not an aggregate, so it cannot + // be brace-initialized. Thus, there is no way to create an object + // of this class. We issue a warning with -Wextra. + const int i; // { dg-warning "const" } +private: + int j; +}; diff --git a/gcc/testsuite/g++.dg/warn/Wextra-2.C b/gcc/testsuite/g++.dg/warn/Wextra-2.C new file mode 100644 index 000000000..5ca41c39d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wextra-2.C @@ -0,0 +1,15 @@ +// { dg-options "-Wextra" } + +struct S { + S(); +}; + +struct T { +private: + int i; +public: + // There should be no warning about this data member because the + // default constructor for "T" will invoke the default constructor + // for "S", even though "S" is "const". + const S s; // { dg-bogus "const" } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C b/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C new file mode 100644 index 000000000..36b3fa53f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wfloat-equal-1.C @@ -0,0 +1,10 @@ +/* PR c/19999 */ +/* { dg-do compile } */ +/* { dg-options "-Wfloat-equal" } */ + +double a, b; +_Complex double c, d; +int f(void) { return a == b; } /* { dg-warning "comparing floating point" } */ +int g(void) { return c == d; } /* { dg-warning "comparing floating point" } */ +int h(void) { return a != b; } /* { dg-warning "comparing floating point" } */ +int i(void) { return c != d; } /* { dg-warning "comparing floating point" } */ diff --git a/gcc/testsuite/g++.dg/warn/Winline-1.C b/gcc/testsuite/g++.dg/warn/Winline-1.C new file mode 100644 index 000000000..e1a7e832a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winline-1.C @@ -0,0 +1,10 @@ +// { dg-options "-Winline -O2" } + +static inline int foo(int x); + +int main() +{ + return(foo(17)); +} + +inline int foo(int x) { return(x); } diff --git a/gcc/testsuite/g++.dg/warn/Winline-2.C b/gcc/testsuite/g++.dg/warn/Winline-2.C new file mode 100644 index 000000000..69af34351 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winline-2.C @@ -0,0 +1,5 @@ +// PR c++/10929 +// { dg-options "-Winline -O3" } + +int foo (); +int bar () { return foo (); } diff --git a/gcc/testsuite/g++.dg/warn/Winline-3.C b/gcc/testsuite/g++.dg/warn/Winline-3.C new file mode 100644 index 000000000..1c226d1b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winline-3.C @@ -0,0 +1,10 @@ +// { dg-options "-Winline -O" } + +#include + +using namespace std; + +int main(void) +{ + vector v(10); +} diff --git a/gcc/testsuite/g++.dg/warn/Winline-4.C b/gcc/testsuite/g++.dg/warn/Winline-4.C new file mode 100644 index 000000000..188ab5aa8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winline-4.C @@ -0,0 +1,17 @@ +// { dg-do compile } +// { dg-options "-O2 -Winline" } +// Origin: +// PR 17115: We should not emit -Winline warning for functions marked with +// noinline + +struct Foo { + __attribute__((noinline)) int a(int r) { return r & 1; } + virtual __attribute__((noinline)) int b(int r) { return r & 1; } + static __attribute__((noinline)) int c(int r) { return r & 1; } +}; + +int bar(int r) { + Foo f; + int k = 1; k &= f.a(r); k &= f.b(r); k &= f.a(r); + return k; +} diff --git a/gcc/testsuite/g++.dg/warn/Wlogical-op-1.C b/gcc/testsuite/g++.dg/warn/Wlogical-op-1.C new file mode 100644 index 000000000..e5b19afbe --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wlogical-op-1.C @@ -0,0 +1,66 @@ +// { dg-do compile } +// { dg-options "-Wlogical-op" } + +enum { a, b1, b2 }; + +enum testenum { t1, t2}; + +extern int c; +extern bool bool_a, bool_b; + +template +class QFlags +{ +public: + typedef void **Zero; + int i; + inline QFlags(Enum f) : i(f) {} + + inline operator int() const + { return i;} + +}; + +QFlags f(t2); +extern void do_something(int); + +extern testenum testa(); + +void foo() +{ + if ( f && b2 ) // { dg-warning "logical" } + do_something(1); + if ( c && b2 ) // { dg-warning "logical" } + do_something(2); + + if ( b2 && c == a ) // { dg-bogus "logical" } + do_something(101); + if ( 1 && c ) + do_something(102); // { dg-bogus "logical" } + if ( t2 && b2 ) // { dg-bogus "logical" } + do_something(103); + if ( true && c == a ) // { dg-bogus "logical" } + do_something(104); + if ( b2 && true ) // { dg-bogus "logical" } + do_something(105); +} + + +void bar() +{ + if ( f || b2 ) // { dg-warning "logical" } + do_something(1); + if ( c || b2 ) // { dg-warning "logical" } + do_something(2); + + if ( b2 || c == a ) // { dg-bogus "logical" } + do_something(101); + if ( 1 || c ) + do_something(102); // { dg-bogus "logical" } + if ( t2 || b2 ) // { dg-bogus "logical" } + do_something(103); + if ( true || c == a ) // { dg-bogus "logical" } + do_something(104); + if ( b2 || true ) // { dg-bogus "logical" } + do_something(105); +} diff --git a/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C b/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C new file mode 100644 index 000000000..894432519 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmissing-declarations-1.C @@ -0,0 +1,45 @@ +// { dg-options "-Wmissing-declarations" } + +void fn1() { } // { dg-warning "no previous declaration" } +namespace ns { + void fn2() { } // { dg-warning "no previous declaration" } +} +namespace { + void fn3() { } +} +static void fn4() { } + +void fn5(); +namespace ns { + void fn6(); +} + +void fn5() { } +namespace ns { + void fn6() { } +} + +inline void fn7() { } + +class c { + void cfn1() { } + static void cfn2() { } + void cfn3(); + static void cfn4(); +}; + +void c::cfn3() { } +void c::cfn4() { } + +static struct { + void sfn1() { } + static void sfn2() { } +} s; + +template +void tfn1() { } + +template void tfn1(); + +class d { }; +template<> void tfn1() { } diff --git a/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C b/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C new file mode 100644 index 000000000..937628ee9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wno-div-by-zero.C @@ -0,0 +1,8 @@ +// { dg-options "-Wno-div-by-zero" } + +int breakme() +{ + int x = 0; + x /= 0; + return x; +} diff --git a/gcc/testsuite/g++.dg/warn/Wnvdtor-2.C b/gcc/testsuite/g++.dg/warn/Wnvdtor-2.C new file mode 100644 index 000000000..d40de3d7c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wnvdtor-2.C @@ -0,0 +1,54 @@ +// PR c++/7302 +// { dg-do compile } +// { dg-options "-Wnon-virtual-dtor" } + +// Warn when a class has virtual functions and accessible non-virtual +// destructor, in which case it would be possible but unsafe to delete +// an instance of a derived class through a pointer to the base class. + +struct A // { dg-bogus "non-virtual destructor" } +{ +protected: + ~A(); +public: + virtual void f() = 0; +}; + +struct B // { dg-bogus "non-virtual destructor" } +{ +private: + ~B(); +public: + virtual void f() = 0; +}; + +struct C // { dg-warning "non-virtual destructor" } +{ + virtual void f() = 0; +}; + +struct D // { dg-warning "non-virtual destructor" } +{ + ~D(); + virtual void f() = 0; +}; + +struct E; + +struct F // { dg-warning "non-virtual destructor" } +{ +protected: + friend class E; + ~F(); +public: + virtual void f() = 0; +}; + +struct G // { dg-warning "non-virtual destructor" } +{ +private: + friend class E; + ~G(); +public: + virtual void f() = 0; +}; diff --git a/gcc/testsuite/g++.dg/warn/Wnvdtor.C b/gcc/testsuite/g++.dg/warn/Wnvdtor.C new file mode 100644 index 000000000..b04fdcbe6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wnvdtor.C @@ -0,0 +1,10 @@ +// { dg-options "-Wnon-virtual-dtor" } + +extern "Java" +{ + class Foo + { + public: + virtual void bar( void); + }; +} diff --git a/gcc/testsuite/g++.dg/warn/Woverflow-1.C b/gcc/testsuite/g++.dg/warn/Woverflow-1.C new file mode 100644 index 000000000..064af4561 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Woverflow-1.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include + +int foo = INT_MAX + 1; /* { dg-warning "integer overflow" } */ + diff --git a/gcc/testsuite/g++.dg/warn/Woverflow-2.C b/gcc/testsuite/g++.dg/warn/Woverflow-2.C new file mode 100644 index 000000000..44368b66f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Woverflow-2.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Woverflow" } */ + +#include + +int foo = INT_MAX + 1; /* { dg-warning "integer overflow" } */ + diff --git a/gcc/testsuite/g++.dg/warn/Woverflow-3.C b/gcc/testsuite/g++.dg/warn/Woverflow-3.C new file mode 100644 index 000000000..73a021b59 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Woverflow-3.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-overflow" } */ + +#include + +int foo = INT_MAX + 1; + diff --git a/gcc/testsuite/g++.dg/warn/Woverloaded-1.C b/gcc/testsuite/g++.dg/warn/Woverloaded-1.C new file mode 100644 index 000000000..65a408b47 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Woverloaded-1.C @@ -0,0 +1,17 @@ +/* { dg-options "-Woverloaded-virtual" } */ + +class Base { +public: + virtual ~Base() { + } +}; + +class Derived: public Base { +public: + int Base() { // There should be no error here. + return 5; + } +}; + +int main() { +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-1.C b/gcc/testsuite/g++.dg/warn/Wparentheses-1.C new file mode 100644 index 000000000..34cb58fc7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-1.C @@ -0,0 +1,68 @@ +// Test operation of -Wparentheses. Warnings for assignments used as +// truth-values. Essentially the same as gcc.dg/Wparentheses-3.c. +// Origin: Joseph Myers + +// { dg-do compile } +// { dg-options "-Wparentheses" } + +int foo (int); + +int a, b, c; +bool d; + +void +bar (void) +{ + if (a = b) // { dg-warning "assignment" "correct warning" } + foo (0); + if ((a = b)) + foo (1); + if (a = a) // { dg-warning "assignment" "correct warning" } + foo (2); + if ((a = a)) + foo (3); + if (b = c) // { dg-warning "assignment" "correct warning" } + foo (4); + else + foo (5); + if ((b = c)) + foo (6); + else + foo (7); + if (b = b) // { dg-warning "assignment" "correct warning" } + foo (8); + else + foo (9); + if ((b = b)) + foo (10); + else + foo (11); + while (c = b) // { dg-warning "assignment" "correct warning" } + foo (12); + while ((c = b)) + foo (13); + while (c = c) // { dg-warning "assignment" "correct warning" } + foo (14); + while ((c = c)) + foo (15); + do foo (16); while (a = b); // { dg-warning "assignment" "correct warning" } + do foo (17); while ((a = b)); + do foo (18); while (a = a); // { dg-warning "assignment" "correct warning" } + do foo (19); while ((a = a)); + for (;c = b;) // { dg-warning "assignment" "correct warning" } + foo (20); + for (;(c = b);) + foo (21); + for (;c = c;) // { dg-warning "assignment" "correct warning" } + foo (22); + for (;(c = c);) + foo (23); + d = a = b; // { dg-warning "assignment" "correct warning" } + foo (24); + d = (a = b); + foo (25); + d = a = a; // { dg-warning "assignment" "correct warning" } + foo (26); + d = (a = a); + foo (27); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-10.C b/gcc/testsuite/g++.dg/warn/Wparentheses-10.C new file mode 100644 index 000000000..c30df090f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-10.C @@ -0,0 +1,119 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-7.c + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a & b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) ^ c); + foo (a & (b ^ c)); + foo (1 & 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) ^ c); + foo (1 & (2 ^ c)); + foo (1 & 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) ^ 3); + foo (1 & (2 ^ 3)); + foo (a ^ b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) & c); + foo (a ^ (b & c)); + foo (1 ^ 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) & c); + foo (1 ^ (2 & c)); + foo (1 ^ 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) & 3); + foo (1 ^ (2 & 3)); + foo (a + b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) ^ c); + foo (a + (b ^ c)); + foo (1 + 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) ^ c); + foo (1 + (2 ^ c)); + foo (1 + 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) ^ 3); + foo (1 + (2 ^ 3)); + foo (a ^ b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) + c); + foo (a ^ (b + c)); + foo (1 ^ 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) + c); + foo (1 ^ (2 + c)); + foo (1 ^ 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) + 3); + foo (1 ^ (2 + 3)); + foo (a - b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) ^ c); + foo (a - (b ^ c)); + foo (1 - 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) ^ c); + foo (1 - (2 ^ c)); + foo (1 - 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) ^ 3); + foo (1 - (2 ^ 3)); + foo (a ^ b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) - c); + foo (a ^ (b - c)); + foo (1 ^ 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) - c); + foo (1 ^ (2 - c)); + foo (1 ^ 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) - 3); + foo (1 ^ (2 - 3)); + foo (a >= b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a >= b) ^ c); + foo (a >= (b ^ c)); + foo (1 >= 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 >= 2) ^ c); + foo (1 >= (2 ^ c)); + foo (1 >= 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 >= 2) ^ 3); + foo (1 >= (2 ^ 3)); + foo (a ^ b >= c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) >= c); + foo (a ^ (b >= c)); + foo (1 ^ 2 >= c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) >= c); + foo (1 ^ (2 >= c)); + foo (1 ^ 2 >= 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) >= 3); + foo (1 ^ (2 >= 3)); + foo (a == b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a == b) ^ c); + foo (a == (b ^ c)); + foo (1 == 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) ^ c); + foo (1 == (2 ^ c)); + foo (1 == 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) ^ 3); + foo (1 == (2 ^ 3)); + foo (a ^ b == c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) == c); + foo (a ^ (b == c)); + foo (1 ^ 2 == c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) == c); + foo (1 ^ (2 == c)); + foo (1 ^ 2 == 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) == 3); + foo (1 ^ (2 == 3)); + foo (a < b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a < b) ^ c); + foo (a < (b ^ c)); + foo (1 < 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) ^ c); + foo (1 < (2 ^ c)); + foo (1 < 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) ^ 3); + foo (1 < (2 ^ 3)); + foo (a ^ b < c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) < c); + foo (a ^ (b < c)); + foo (1 ^ 2 < c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) < c); + foo (1 ^ (2 < c)); + foo (1 ^ 2 < 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) < 3); + foo (1 ^ (2 < 3)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-11.C b/gcc/testsuite/g++.dg/warn/Wparentheses-11.C new file mode 100644 index 000000000..912c3b7ae --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-11.C @@ -0,0 +1,101 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-8.c + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a + b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) & c); + foo (a + (b & c)); + foo (1 + 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) & c); + foo (1 + (2 & c)); + foo (1 + 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) & 3); + foo (1 + (2 & 3)); + foo (a & b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) + c); + foo (a & (b + c)); + foo (1 & 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) + c); + foo (1 & (2 + c)); + foo (1 & 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) + 3); + foo (1 & (2 + 3)); + foo (a - b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) & c); + foo (a - (b & c)); + foo (1 - 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) & c); + foo (1 - (2 & c)); + foo (1 - 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) & 3); + foo (1 - (2 & 3)); + foo (a & b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) - c); + foo (a & (b - c)); + foo (1 & 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) - c); + foo (1 & (2 - c)); + foo (1 & 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) - 3); + foo (1 & (2 - 3)); + foo (a < b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a < b) & c); + foo (a < (b & c)); + foo (1 < 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) & c); + foo (1 < (2 & c)); + foo (1 < 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) & 3); + foo (1 < (2 & 3)); + foo (a & b < c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) < c); + foo (a & (b < c)); + foo (1 & 2 < c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) < c); + foo (1 & (2 < c)); + foo (1 & 2 < 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) < 3); + foo (1 & (2 < 3)); + foo (a == b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a == b) & c); + foo (a == (b & c)); + foo (1 == 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) & c); + foo (1 == (2 & c)); + foo (1 == 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) & 3); + foo (1 == (2 & 3)); + foo (a & b == c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) == c); + foo (a & (b == c)); + foo (1 & 2 == c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) == c); + foo (1 & (2 == c)); + foo (1 & 2 == 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) == 3); + foo (1 & (2 == 3)); + foo (a != b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a != b) & c); + foo (a != (b & c)); + foo (1 != 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 != 2) & c); + foo (1 != (2 & c)); + foo (1 != 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 != 2) & 3); + foo (1 != (2 & 3)); + foo (a & b != c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) != c); + foo (a & (b != c)); + foo (1 & 2 != c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) != c); + foo (1 & (2 != c)); + foo (1 & 2 != 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) != 3); + foo (1 & (2 != 3)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-12.C b/gcc/testsuite/g++.dg/warn/Wparentheses-12.C new file mode 100644 index 000000000..b04529827 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-12.C @@ -0,0 +1,60 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-9.c + +int foo (int); + +int a, b, c; + +int +bar (void) +{ + if (a) + foo (0); + if (b) + foo (1); + else + foo (2); + if (c) // { dg-warning "ambiguous" "correct warning" } + if (a) + foo (3); + else + foo (4); + if (a) + if (c) + foo (5); + if (a) + if (b) // { dg-warning "ambiguous" "correct warning" } + if (c) + foo (6); + else + foo (7); + if (a) // { dg-warning "ambiguous" "correct warning" } + if (b) + if (c) + foo (8); + else + foo (9); + else + foo (10); + if (a) + if (b) + if (c) + foo (11); + else + foo (12); + else + foo (13); + else + foo (14); + if (a) { + if (b) + if (c) + foo (15); + else + foo (16); + else + foo (17); + } +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-13.C b/gcc/testsuite/g++.dg/warn/Wparentheses-13.C new file mode 100644 index 000000000..ebe8f426a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-13.C @@ -0,0 +1,69 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-1.C. + +int foo (int); + +int a, b, c; +bool d; + +template +void +bar (T) +{ + if (a = b) // { dg-warning "assignment" "correct warning" } + foo (0); + if ((a = b)) + foo (1); + if (a = a) // { dg-warning "assignment" "correct warning" } + foo (2); + if ((a = a)) + foo (3); + if (b = c) // { dg-warning "assignment" "correct warning" } + foo (4); + else + foo (5); + if ((b = c)) + foo (6); + else + foo (7); + if (b = b) // { dg-warning "assignment" "correct warning" } + foo (8); + else + foo (9); + if ((b = b)) + foo (10); + else + foo (11); + while (c = b) // { dg-warning "assignment" "correct warning" } + foo (12); + while ((c = b)) + foo (13); + while (c = c) // { dg-warning "assignment" "correct warning" } + foo (14); + while ((c = c)) + foo (15); + do foo (16); while (a = b); // { dg-warning "assignment" "correct warning" } + do foo (17); while ((a = b)); + do foo (18); while (a = a); // { dg-warning "assignment" "correct warning" } + do foo (19); while ((a = a)); + for (;c = b;) // { dg-warning "assignment" "correct warning" } + foo (20); + for (;(c = b);) + foo (21); + for (;c = c;) // { dg-warning "assignment" "correct warning" } + foo (22); + for (;(c = c);) + foo (23); + d = a = b; // { dg-warning "assignment" "correct warning" } + foo (24); + d = (a = b); + foo (25); + d = a = a; // { dg-warning "assignment" "correct warning" } + foo (26); + d = (a = a); + foo (27); +} + +template void bar (int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-14.C b/gcc/testsuite/g++.dg/warn/Wparentheses-14.C new file mode 100644 index 000000000..67bd43ec5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-14.C @@ -0,0 +1,43 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-2.C. + +int foo (int); + +int a, b, c; +bool d; + +template +void +bar (T) +{ + if (a += b) + foo (0); + if (a -= a) + foo (1); + if (b *= c) + foo (2); + else + foo (3); + if (b /= b) + foo (4); + else + foo (5); + while (c %= b) + foo (6); + while (c <<= c) + foo (7); + do foo (8); while (a >>= b); + do foo (9); while (a &= a); + for (;c ^= b;) + foo (10); + for (;c |= c;) + foo (11); + d = a += b; + foo (12); + d = a -= a; + foo (13); +} + +template void bar (int); diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-15.C b/gcc/testsuite/g++.dg/warn/Wparentheses-15.C new file mode 100644 index 000000000..db73d430a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-15.C @@ -0,0 +1,68 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-6.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a <= b <= c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) <= c); + foo (a <= (b <= c)); + foo (1 <= 2 <= c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) <= c); + foo (1 <= (2 <= c)); + foo (1 <= 2 <= 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) <= 3); + foo (1 <= (2 <= 3)); + foo (a > b > c); // { dg-warning "comparison" "correct warning" } + foo ((a > b) > c); + foo (a > (b > c)); + foo (1 > 2 > c); // { dg-warning "comparison" "correct warning" } + foo ((1 > 2) > c); + foo (1 > (2 > c)); + foo (1 > 2 > 3); // { dg-warning "comparison" "correct warning" } + foo ((1 > 2) > 3); + foo (1 > (2 > 3)); + foo (a < b <= c); // { dg-warning "comparison" "correct warning" } + foo ((a < b) <= c); + foo (a < (b <= c)); + foo (1 < 2 <= c); // { dg-warning "comparison" "correct warning" } + foo ((1 < 2) <= c); + foo (1 < (2 <= c)); + foo (1 < 2 <= 3); // { dg-warning "comparison" "correct warning" } + foo ((1 < 2) <= 3); + foo (1 < (2 <= 3)); + foo (a <= b > c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) > c); + foo (a <= (b > c)); + foo (1 <= 2 > c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) > c); + foo (1 <= (2 > c)); + foo (1 <= 2 > 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) > 3); + foo (1 <= (2 > 3)); + foo (a <= b == c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) == c); + foo (a <= (b == c)); + foo (1 <= 2 == c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) == c); + foo (1 <= (2 == c)); + foo (1 <= 2 == 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) == 3); + foo (1 <= (2 == 3)); + foo (a != b != c); // { dg-warning "comparison" "correct warning" } + foo ((a != b) != c); + foo (a != (b != c)); + foo (1 != 2 != c); // { dg-warning "comparison" "correct warning" } + foo ((1 != 2) != c); + foo (1 != (2 != c)); + foo (1 != 2 != 3); // { dg-warning "comparison" "correct warning" } + foo ((1 != 2) != 3); + foo (1 != (2 != 3)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-16.C b/gcc/testsuite/g++.dg/warn/Wparentheses-16.C new file mode 100644 index 000000000..638155237 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-16.C @@ -0,0 +1,86 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-7.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a + b << c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) << c); + foo (a + (b << c)); + foo (1 + 2 << c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) << c); + foo (1 + (2 << c)); + foo (1 + 2 << 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) << 3); + foo (1 + (2 << 3)); + foo (a << b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a << b) + c); + foo (a << (b + c)); + foo (1 << 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 << 2) + c); + foo (1 << (2 + c)); + foo (1 << 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 << 2) + 3); + foo (1 << (2 + 3)); + foo (a + b >> c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) >> c); + foo (a + (b >> c)); + foo (1 + 2 >> c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) >> c); + foo (1 + (2 >> c)); + foo (1 + 2 >> 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) >> 3); + foo (1 + (2 >> 3)); + foo (a >> b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a >> b) + c); + foo (a >> (b + c)); + foo (1 >> 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 >> 2) + c); + foo (1 >> (2 + c)); + foo (1 >> 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 >> 2) + 3); + foo (1 >> (2 + 3)); + foo (a - b << c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) << c); + foo (a - (b << c)); + foo (6 - 5 << c); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) << c); + foo (6 - (5 << c)); + foo (6 - 5 << 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) << 4); + foo (6 - (5 << 4)); + foo (a << b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a << b) - c); + foo (a << (b - c)); + foo (6 << 5 - c); // { dg-warning "parentheses" "correct warning" } + foo ((6 << 5) - c); + foo (6 << (5 - c)); + foo (6 << 5 - 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 << 5) - 4); + foo (6 << (5 - 4)); + foo (a - b >> c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) >> c); + foo (a - (b >> c)); + foo (6 - 5 >> c); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) >> c); + foo (6 - (5 >> c)); + foo (6 - 5 >> 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) >> 4); + foo (6 - (5 >> 4)); + foo (a >> b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a >> b) - c); + foo (a >> (b - c)); + foo (6 >> 5 - c); // { dg-warning "parentheses" "correct warning" } + foo ((6 >> 5) - c); + foo (6 >> (5 - c)); + foo (6 >> 5 - 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 >> 5) - 4); + foo (6 >> (5 - 4)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-17.C b/gcc/testsuite/g++.dg/warn/Wparentheses-17.C new file mode 100644 index 000000000..1af1e2e03 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-17.C @@ -0,0 +1,32 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-8.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a && b || c); // { dg-warning "parentheses" "correct warning" } + foo ((a && b) || c); + foo (a && (b || c)); + foo (1 && 2 || c); // { dg-warning "parentheses" "correct warning" } + foo ((1 && 2) || c); + foo (1 && (2 || c)); + foo (1 && 2 || 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 && 2) || 3); + foo (1 && (2 || 3)); + foo (a || b && c); // { dg-warning "parentheses" "correct warning" } + foo ((a || b) && c); + foo (a || (b && c)); + foo (1 || 2 && c); // { dg-warning "parentheses" "correct warning" } + foo ((1 || 2) && c); + foo (1 || (2 && c)); + foo (1 || 2 && 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 || 2) && 3); + foo (1 || (2 && 3)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-18.C b/gcc/testsuite/g++.dg/warn/Wparentheses-18.C new file mode 100644 index 000000000..d562315f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-18.C @@ -0,0 +1,122 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-9.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a & b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) | c); + foo (a & (b | c)); + foo (1 & 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) | c); + foo (1 & (2 | c)); + foo (1 & 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) | 3); + foo (1 & (2 | 3)); + foo (a | b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) & c); + foo (a | (b & c)); + foo (1 | 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) & c); + foo (1 | (2 & c)); + foo (1 | 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) & 3); + foo (1 | (2 & 3)); + foo (a ^ b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) | c); + foo (a ^ (b | c)); + foo (1 ^ 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) | c); + foo (1 ^ (2 | c)); + foo (1 ^ 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) | 3); + foo (1 ^ (2 | 3)); + foo (a | b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) ^ c); + foo (a | (b ^ c)); + foo (1 | 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) ^ c); + foo (1 | (2 ^ c)); + foo (1 | 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) ^ 3); + foo (1 | (2 ^ 3)); + foo (a + b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) | c); + foo (a + (b | c)); + foo (1 + 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) | c); + foo (1 + (2 | c)); + foo (1 + 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) | 3); + foo (1 + (2 | 3)); + foo (a | b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) + c); + foo (a | (b + c)); + foo (1 | 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) + c); + foo (1 | (2 + c)); + foo (1 | 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) + 3); + foo (1 | (2 + 3)); + foo (a - b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) | c); + foo (a - (b | c)); + foo (1 - 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) | c); + foo (1 - (2 | c)); + foo (1 - 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) | 3); + foo (1 - (2 | 3)); + foo (a | b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) - c); + foo (a | (b - c)); + foo (1 | 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) - c); + foo (1 | (2 - c)); + foo (1 | 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) - 3); + foo (1 | (2 - 3)); + foo (a > b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a > b) | c); + foo (a > (b | c)); + foo (1 > 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 > 2) | c); + foo (1 > (2 | c)); + foo (1 > 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 > 2) | 3); + foo (1 > (2 | 3)); + foo (a | b > c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) > c); + foo (a | (b > c)); + foo (1 | 2 > c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) > c); + foo (1 | (2 > c)); + foo (1 | 2 > 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) > 3); + foo (1 | (2 > 3)); + foo (a <= b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a <= b) | c); + foo (a <= (b | c)); + foo (1 <= 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 <= 2) | c); + foo (1 <= (2 | c)); + foo (1 <= 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 <= 2) | 3); + foo (1 <= (2 | 3)); + foo (a | b <= c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) <= c); + foo (a | (b <= c)); + foo (1 | 2 <= c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) <= c); + foo (1 | (2 <= c)); + foo (1 | 2 <= 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) <= 3); + foo (1 | (2 <= 3)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-19.C b/gcc/testsuite/g++.dg/warn/Wparentheses-19.C new file mode 100644 index 000000000..e3dfc5d05 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-19.C @@ -0,0 +1,122 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-10.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a & b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) ^ c); + foo (a & (b ^ c)); + foo (1 & 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) ^ c); + foo (1 & (2 ^ c)); + foo (1 & 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) ^ 3); + foo (1 & (2 ^ 3)); + foo (a ^ b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) & c); + foo (a ^ (b & c)); + foo (1 ^ 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) & c); + foo (1 ^ (2 & c)); + foo (1 ^ 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) & 3); + foo (1 ^ (2 & 3)); + foo (a + b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) ^ c); + foo (a + (b ^ c)); + foo (1 + 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) ^ c); + foo (1 + (2 ^ c)); + foo (1 + 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) ^ 3); + foo (1 + (2 ^ 3)); + foo (a ^ b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) + c); + foo (a ^ (b + c)); + foo (1 ^ 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) + c); + foo (1 ^ (2 + c)); + foo (1 ^ 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) + 3); + foo (1 ^ (2 + 3)); + foo (a - b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) ^ c); + foo (a - (b ^ c)); + foo (1 - 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) ^ c); + foo (1 - (2 ^ c)); + foo (1 - 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) ^ 3); + foo (1 - (2 ^ 3)); + foo (a ^ b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) - c); + foo (a ^ (b - c)); + foo (1 ^ 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) - c); + foo (1 ^ (2 - c)); + foo (1 ^ 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) - 3); + foo (1 ^ (2 - 3)); + foo (a >= b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a >= b) ^ c); + foo (a >= (b ^ c)); + foo (1 >= 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 >= 2) ^ c); + foo (1 >= (2 ^ c)); + foo (1 >= 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 >= 2) ^ 3); + foo (1 >= (2 ^ 3)); + foo (a ^ b >= c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) >= c); + foo (a ^ (b >= c)); + foo (1 ^ 2 >= c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) >= c); + foo (1 ^ (2 >= c)); + foo (1 ^ 2 >= 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) >= 3); + foo (1 ^ (2 >= 3)); + foo (a == b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a == b) ^ c); + foo (a == (b ^ c)); + foo (1 == 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) ^ c); + foo (1 == (2 ^ c)); + foo (1 == 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) ^ 3); + foo (1 == (2 ^ 3)); + foo (a ^ b == c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) == c); + foo (a ^ (b == c)); + foo (1 ^ 2 == c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) == c); + foo (1 ^ (2 == c)); + foo (1 ^ 2 == 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) == 3); + foo (1 ^ (2 == 3)); + foo (a < b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a < b) ^ c); + foo (a < (b ^ c)); + foo (1 < 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) ^ c); + foo (1 < (2 ^ c)); + foo (1 < 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) ^ 3); + foo (1 < (2 ^ 3)); + foo (a ^ b < c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) < c); + foo (a ^ (b < c)); + foo (1 ^ 2 < c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) < c); + foo (1 ^ (2 < c)); + foo (1 ^ 2 < 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) < 3); + foo (1 ^ (2 < 3)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-2.C b/gcc/testsuite/g++.dg/warn/Wparentheses-2.C new file mode 100644 index 000000000..286e2f97c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-2.C @@ -0,0 +1,43 @@ +// Test operation of -Wparentheses. Warnings for assignments used as +// truth-values shouldn't apply other than for plain assignment. +// Essentially the same as gcc.dg/Wparentheses-10.c. +// Origin: Joseph Myers + +// { dg-do compile } +// { dg-options "-Wparentheses" } + +int foo (int); + +int a, b, c; +bool d; + +void +bar (void) +{ + if (a += b) + foo (0); + if (a -= a) + foo (1); + if (b *= c) + foo (2); + else + foo (3); + if (b /= b) + foo (4); + else + foo (5); + while (c %= b) + foo (6); + while (c <<= c) + foo (7); + do foo (8); while (a >>= b); + do foo (9); while (a &= a); + for (;c ^= b;) + foo (10); + for (;c |= c;) + foo (11); + d = a += b; + foo (12); + d = a -= a; + foo (13); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-20.C b/gcc/testsuite/g++.dg/warn/Wparentheses-20.C new file mode 100644 index 000000000..a1ba89dfc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-20.C @@ -0,0 +1,104 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-11.C. + +int foo (int); + +template +void +bar (T a, T b, T c) +{ + foo (a + b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) & c); + foo (a + (b & c)); + foo (1 + 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) & c); + foo (1 + (2 & c)); + foo (1 + 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) & 3); + foo (1 + (2 & 3)); + foo (a & b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) + c); + foo (a & (b + c)); + foo (1 & 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) + c); + foo (1 & (2 + c)); + foo (1 & 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) + 3); + foo (1 & (2 + 3)); + foo (a - b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) & c); + foo (a - (b & c)); + foo (1 - 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) & c); + foo (1 - (2 & c)); + foo (1 - 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) & 3); + foo (1 - (2 & 3)); + foo (a & b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) - c); + foo (a & (b - c)); + foo (1 & 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) - c); + foo (1 & (2 - c)); + foo (1 & 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) - 3); + foo (1 & (2 - 3)); + foo (a < b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a < b) & c); + foo (a < (b & c)); + foo (1 < 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) & c); + foo (1 < (2 & c)); + foo (1 < 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 < 2) & 3); + foo (1 < (2 & 3)); + foo (a & b < c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) < c); + foo (a & (b < c)); + foo (1 & 2 < c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) < c); + foo (1 & (2 < c)); + foo (1 & 2 < 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) < 3); + foo (1 & (2 < 3)); + foo (a == b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a == b) & c); + foo (a == (b & c)); + foo (1 == 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) & c); + foo (1 == (2 & c)); + foo (1 == 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 == 2) & 3); + foo (1 == (2 & 3)); + foo (a & b == c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) == c); + foo (a & (b == c)); + foo (1 & 2 == c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) == c); + foo (1 & (2 == c)); + foo (1 & 2 == 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) == 3); + foo (1 & (2 == 3)); + foo (a != b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a != b) & c); + foo (a != (b & c)); + foo (1 != 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 != 2) & c); + foo (1 != (2 & c)); + foo (1 != 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 != 2) & 3); + foo (1 != (2 & 3)); + foo (a & b != c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) != c); + foo (a & (b != c)); + foo (1 & 2 != c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) != c); + foo (1 & (2 != c)); + foo (1 & 2 != 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) != 3); + foo (1 & (2 != 3)); +} + +template void bar (int, int, int); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-21.C b/gcc/testsuite/g++.dg/warn/Wparentheses-21.C new file mode 100644 index 000000000..588b4fdb7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-21.C @@ -0,0 +1,66 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-12.C. Note that we currently warn +// when we initially parse the template, not when we are instantiating +// it. That seems reasonable since the template parameters can not +// affect the syntax parsing. + +int foo (int); + +int a, b, c; + +template +void +bar (T) +{ + if (a) + foo (0); + if (b) + foo (1); + else + foo (2); + if (c) // { dg-warning "ambiguous" "correct warning" } + if (a) + foo (3); + else + foo (4); + if (a) + if (c) + foo (5); + if (a) + if (b) // { dg-warning "ambiguous" "correct warning" } + if (c) + foo (6); + else + foo (7); + if (a) // { dg-warning "ambiguous" "correct warning" } + if (b) + if (c) + foo (8); + else + foo (9); + else + foo (10); + if (a) + if (b) + if (c) + foo (11); + else + foo (12); + else + foo (13); + else + foo (14); + if (a) { + if (b) + if (c) + foo (15); + else + foo (16); + else + foo (17); + } +} + +template void bar (int); diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-22.C b/gcc/testsuite/g++.dg/warn/Wparentheses-22.C new file mode 100644 index 000000000..395953dd4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-22.C @@ -0,0 +1,111 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Warnings for assignments used as truth-values when using classes. +// Like Wparentheses-1.C, but with a class. + +int foo (int); + +class C +{ + public: + C() + : b(0) + { } + + // Use default assignment constructor. + + // Provide conversion to bool so that an instance of this class will + // work as a condition. + operator bool() const + { return b != 0; } + + private: + int b; +}; + +C a, b, c; +bool d; + +void +bar (void) +{ + if (a = b) // { dg-warning "assignment" "correct warning" } + foo (0); + if ((a = b)) + foo (1); + if (a = a) // { dg-warning "assignment" "correct warning" } + foo (2); + if ((a = a)) + foo (3); + if (b = c) // { dg-warning "assignment" "correct warning" } + foo (4); + else + foo (5); + if ((b = c)) + foo (6); + else + foo (7); + if (b = b) // { dg-warning "assignment" "correct warning" } + foo (8); + else + foo (9); + if ((b = b)) + foo (10); + else + foo (11); + while (c = b) // { dg-warning "assignment" "correct warning" } + foo (12); + while ((c = b)) + foo (13); + while (c = c) // { dg-warning "assignment" "correct warning" } + foo (14); + while ((c = c)) + foo (15); + do foo (16); while (a = b); // { dg-warning "assignment" "correct warning" } + do foo (17); while ((a = b)); + do foo (18); while (a = a); // { dg-warning "assignment" "correct warning" } + do foo (19); while ((a = a)); + for (;c = b;) // { dg-warning "assignment" "correct warning" } + foo (20); + for (;(c = b);) + foo (21); + for (;c = c;) // { dg-warning "assignment" "correct warning" } + foo (22); + for (;(c = c);) + foo (23); + d = a = b; // { dg-warning "assignment" "correct warning" } + foo (24); + d = (a = b); + foo (25); + d = a = a; // { dg-warning "assignment" "correct warning" } + foo (26); + d = (a = a); + foo (27); + if (C(a)) + foo (28); +} + +bool +bar1 (void) +{ + return a = b; // { dg-warning "assignment" "correct warning" } +} + +bool +bar2 (void) +{ + return (a = b); +} + +bool +bar3 (void) +{ + return a = a; // { dg-warning "assignment" "correct warning" } +} + +bool +bar4 (void) +{ + return (a = a); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-23.C b/gcc/testsuite/g++.dg/warn/Wparentheses-23.C new file mode 100644 index 000000000..cadc287fe --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-23.C @@ -0,0 +1,121 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// Template version of Wparentheses-22.C. + +int foo (int); + +class C +{ + public: + C() + : b(0) + { } + + // Use default assignment constructor. + + // Provide conversion to bool so that an instance of this class will + // work as a condition. + operator bool() const + { return b != 0; } + + private: + int b; +}; + +C a, b, c; +bool d; + +template +void +bar (T) +{ + if (a = b) // { dg-warning "assignment" "correct warning" } + foo (0); + if ((a = b)) + foo (1); + if (a = a) // { dg-warning "assignment" "correct warning" } + foo (2); + if ((a = a)) + foo (3); + if (b = c) // { dg-warning "assignment" "correct warning" } + foo (4); + else + foo (5); + if ((b = c)) + foo (6); + else + foo (7); + if (b = b) // { dg-warning "assignment" "correct warning" } + foo (8); + else + foo (9); + if ((b = b)) + foo (10); + else + foo (11); + while (c = b) // { dg-warning "assignment" "correct warning" } + foo (12); + while ((c = b)) + foo (13); + while (c = c) // { dg-warning "assignment" "correct warning" } + foo (14); + while ((c = c)) + foo (15); + do foo (16); while (a = b); // { dg-warning "assignment" "correct warning" } + do foo (17); while ((a = b)); + do foo (18); while (a = a); // { dg-warning "assignment" "correct warning" } + do foo (19); while ((a = a)); + for (;c = b;) // { dg-warning "assignment" "correct warning" } + foo (20); + for (;(c = b);) + foo (21); + for (;c = c;) // { dg-warning "assignment" "correct warning" } + foo (22); + for (;(c = c);) + foo (23); + d = a = b; // { dg-warning "assignment" "correct warning" } + foo (24); + d = (a = b); + foo (25); + d = a = a; // { dg-warning "assignment" "correct warning" } + foo (26); + d = (a = a); + foo (27); + if (C(a)) + foo (28); +} + +template +bool +bar1 (T) +{ + return a = b; // { dg-warning "assignment" "correct warning" } +} + +template +bool +bar2 (T) +{ + return (a = b); +} + +template +bool +bar3 (T) +{ + return a = a; // { dg-warning "assignment" "correct warning" } +} + +template +bool +bar4 (T) +{ + return (a = a); +} + +template void bar (int); // { dg-message "instantiated" } +template bool bar1 (int); // { dg-message "instantiated" } +template bool bar2 (int); +template bool bar3 (int); // { dg-message "instantiated" } +template bool bar4 (int); diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-24.C b/gcc/testsuite/g++.dg/warn/Wparentheses-24.C new file mode 100644 index 000000000..4019d3d82 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-24.C @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +extern int foo (int); + +bool a, b, c; + +bool +bar () +{ + c = a = b; + foo (0); + return a = b; +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-25.C b/gcc/testsuite/g++.dg/warn/Wparentheses-25.C new file mode 100644 index 000000000..ab00c25f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-25.C @@ -0,0 +1,259 @@ +/* PR 7543. Test operation of -Wparentheses. Precedence warnings. + !a | b and !a & b. */ +/* { dg-do compile } */ +/* { dg-options "-Wparentheses" } */ +// C++ version of Wparentheses-11.c +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (!a & b); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b < c)); + foo (!a & (b > c)); + foo (!a & (b == c)); + foo (!a & (b != c)); + foo (!a & (b <= c)); + foo (!a & (b >= c)); + foo (!a & (b && c)); + foo (!a & (b || c)); + foo (!a & !b); + foo (!(a & b)); + foo ((!a) & b); + foo (!a & 2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 < c)); + foo (!a & (2 > c)); + foo (!a & (2 == c)); + foo (!a & (2 != c)); + foo (!a & (2 <= c)); + foo (!a & (2 >= c)); + foo (!a & (2 && c)); + foo (!a & (2 || c)); + foo (!a & !2); + foo (!(a & 2)); + foo ((!a) & 2); + foo (!1 & 2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 < c)); + foo (!1 & (2 > c)); + foo (!1 & (2 == c)); + foo (!1 & (2 != c)); + foo (!1 & (2 <= c)); + foo (!1 & (2 >= c)); + foo (!1 & (2 && c)); + foo (!1 & (2 || c)); + foo (!1 & !2); + foo (!(1 & 2)); + + foo (!a | b); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b < c)); + foo (!a | (b > c)); + foo (!a | (b == c)); + foo (!a | (b != c)); + foo (!a | (b <= c)); + foo (!a | (b >= c)); + foo (!a | (b && c)); + foo (!a | (b || c)); + foo (!a | !b); + foo (!(a | b)); + foo ((!a) | b); + foo (!a | 2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 < c)); + foo (!a | (2 > c)); + foo (!a | (2 == c)); + foo (!a | (2 != c)); + foo (!a | (2 <= c)); + foo (!a | (2 >= c)); + foo (!a | (2 && c)); + foo (!a | (2 || c)); + foo (!a | !2); + foo (!(a | 2)); + foo ((!a) | 2); + foo (!1 | 2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 < c)); + foo (!1 | (2 > c)); + foo (!1 | (2 == c)); + foo (!1 | (2 != c)); + foo (!1 | (2 <= c)); + foo (!1 | (2 >= c)); + foo (!1 | (2 && c)); + foo (!1 | (2 || c)); + foo (!1 | !2); + foo (!(1 | 2)); + foo ((!1) | 2); + + foo (b & !a); /* { dg-bogus "parentheses" "bogus warning" } */ + foo ((b < c) & !a); + foo ((b > c) & !a); + foo ((b == c) & !a); + foo ((b != c) & !a); + foo ((b <= c) & !a); + foo ((b >= c) & !a); + foo ((b && c) & !a); + foo ((b || c) & !a); + foo (!b & !a); + foo (!(b & a)); + foo (b & (!a)); + foo (2 & !a); /* { dg-bogus "parentheses" "correct warning" } */ + foo ((2 < c) & !a); + foo ((2 > c) & !a); + foo ((2 == c) & !a); + foo ((2 != c) & !a); + foo ((2 <= c) & !a); + foo ((2 >= c) & !a); + foo ((2 && c) & !a); + foo ((2 || c) & !a); + foo (!2 & !a); + foo (!(2 & a)); + foo (2 & (!a)); + foo (2 & !1); /* { dg-bogus "parentheses" "correct warning" } */ + foo ((2 < c) & !1); + foo ((2 > c) & !1); + foo ((2 == c) & !1); + foo ((2 != c) & !1); + foo ((2 <= c) & !1); + foo ((2 >= c) & !1); + foo ((2 && c) & !1); + foo ((2 || c) & !1); + foo (!2 & !1); + foo (!(2 & 1)); + + foo (b | !a); /* { dg-bogus "parentheses" "correct warning" } */ + foo ((b < c) | !a); + foo ((b > c) | !a); + foo ((b == c) | !a); + foo ((b != c) | !a); + foo ((b <= c) | !a); + foo ((b >= c) | !a); + foo ((b && c) | !a); + foo ((b || c) | !a); + foo (!b | !a); + foo (!(b | a)); + foo (b | (!a)); + foo (2 | !a); /* { dg-bogus "parentheses" "correct warning" } */ + foo ((2 < c) | !a); + foo ((2 > c) | !a); + foo ((2 == c) | !a); + foo ((2 != c) | !a); + foo ((2 <= c) | !a); + foo ((2 >= c) | !a); + foo ((2 && c) | !a); + foo ((2 || c) | !a); + foo (!2 | !a); + foo (!(2 | a)); + foo (2 | (!a)); + foo (2 | !1); /* { dg-bogus "parentheses" "correct warning" } */ + foo ((2 < c) | !1); + foo ((2 > c) | !1); + foo ((2 == c) | !1); + foo ((2 != c) | !1); + foo ((2 <= c) | !1); + foo ((2 >= c) | !1); + foo ((2 && c) | !1); + foo ((2 || c) | !1); + foo (!2 | !1); + foo (!(2 | 1)); + foo (2 | (!1)); +} + + +int +baz (int a, int b, int c) +{ + foo (!a & (b << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b = c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & ~b); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (b | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & 2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (c = 2)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & ~2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a & (2 | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (c = 2)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & ~2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 & (2 | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b = c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | ~b); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (b | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (c = 2)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | ~2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!a | (2 | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 << c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 >> c));/* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 + c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 - c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (c = 2)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | ~2); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 & c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo (!1 | (2 | c)); /* { dg-warning "parentheses" "correct warning" { xfail *-*-* } } */ + foo ((b << c) & !a); + foo ((b >> c) & !a); + foo ((b + c) & !a); + foo ((b - c) & !a); + foo ((b = c) & !a); + foo (~b & !a); + foo ((b & c) & !a); + foo ((b | c) & !a); + foo ((2 << c) & !a); + foo ((2 >> c) & !a); + foo ((2 + c) & !a); + foo ((2 - c) & !a); + foo ((c = 2) & !a); + foo (~2 & !a); + foo ((2 & c) & !a); + foo ((2 | c) & !a); + foo ((2 << c) & !1); + foo ((2 >> c) & !1); + foo ((2 + c) & !1); + foo ((2 - c) & !1); + foo ((c = 2) & !1); + foo (~2 & !1); + foo ((2 & c) & !1); + foo ((2 | c) & !1); + foo ((b << c) | !a); + foo ((b >> c) | !a); + foo ((b + c) | !a); + foo ((b - c) | !a); + foo ((b = c) | !a); + foo (~b | !a); + foo ((b & c) | !a); + foo ((b | c) | !a); + foo ((2 << c) | !a); + foo ((2 >> c) | !a); + foo ((2 + c) | !a); + foo ((2 - c) | !a); + foo ((c = 2) | !a); + foo (~2 | !a); + foo ((2 & c) | !a); + foo ((2 | c) | !a); + foo ((2 << c) | !1); + foo ((2 >> c) | !1); + foo ((2 + c) | !1); + foo ((2 - c) | !1); + foo ((c = 2) | !1); + foo (~2 | !1); + foo ((2 & c) | !1); + foo ((2 | c) | !1); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-3.C b/gcc/testsuite/g++.dg/warn/Wparentheses-3.C new file mode 100644 index 000000000..8781953b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-3.C @@ -0,0 +1,13 @@ +// Test that -Wparentheses does not give bogus warnings in the +// presence of templates. Bug 17041. + +// { dg-do compile } +// { dg-options "-Wparentheses" } + +template struct A +{ + int i; + A() { if ((i = 0)) ; } +}; + +A<0> a; diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-4.C b/gcc/testsuite/g++.dg/warn/Wparentheses-4.C new file mode 100644 index 000000000..2048ed7c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-4.C @@ -0,0 +1,19 @@ +// Test that -Wparentheses does not give bogus warnings in the +// presence of templates for non-plain assignment. Bug 17120. + +// { dg-do compile } +// { dg-options "-Wparentheses" } + +template + inline _Tp + cmath_power(_Tp __x, unsigned int __n) + { + while (__n >>= 1) + ; + return __x; + } + +int main() +{ + cmath_power(1.0, 3); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-5.C b/gcc/testsuite/g++.dg/warn/Wparentheses-5.C new file mode 100644 index 000000000..2cd05aaae --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-5.C @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options -Wparentheses } + +// C++ version of gcc.dg/Wparentheses-1.c. + +int foo (int a, int b) +{ + int c = (a && b) || 0; // { dg-bogus "suggest parentheses" } + c = a && b || 0; // { dg-warning "suggest parentheses" } + + return (a && b && 1) || 0; // { dg-bogus "suggest parentheses" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-6.C b/gcc/testsuite/g++.dg/warn/Wparentheses-6.C new file mode 100644 index 000000000..9963d822e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-6.C @@ -0,0 +1,65 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-2.c. + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a <= b <= c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) <= c); + foo (a <= (b <= c)); + foo (1 <= 2 <= c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) <= c); + foo (1 <= (2 <= c)); + foo (1 <= 2 <= 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) <= 3); + foo (1 <= (2 <= 3)); + foo (a > b > c); // { dg-warning "comparison" "correct warning" } + foo ((a > b) > c); + foo (a > (b > c)); + foo (1 > 2 > c); // { dg-warning "comparison" "correct warning" } + foo ((1 > 2) > c); + foo (1 > (2 > c)); + foo (1 > 2 > 3); // { dg-warning "comparison" "correct warning" } + foo ((1 > 2) > 3); + foo (1 > (2 > 3)); + foo (a < b <= c); // { dg-warning "comparison" "correct warning" } + foo ((a < b) <= c); + foo (a < (b <= c)); + foo (1 < 2 <= c); // { dg-warning "comparison" "correct warning" } + foo ((1 < 2) <= c); + foo (1 < (2 <= c)); + foo (1 < 2 <= 3); // { dg-warning "comparison" "correct warning" } + foo ((1 < 2) <= 3); + foo (1 < (2 <= 3)); + foo (a <= b > c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) > c); + foo (a <= (b > c)); + foo (1 <= 2 > c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) > c); + foo (1 <= (2 > c)); + foo (1 <= 2 > 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) > 3); + foo (1 <= (2 > 3)); + foo (a <= b == c); // { dg-warning "comparison" "correct warning" } + foo ((a <= b) == c); + foo (a <= (b == c)); + foo (1 <= 2 == c); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) == c); + foo (1 <= (2 == c)); + foo (1 <= 2 == 3); // { dg-warning "comparison" "correct warning" } + foo ((1 <= 2) == 3); + foo (1 <= (2 == 3)); + foo (a != b != c); // { dg-warning "comparison" "correct warning" } + foo ((a != b) != c); + foo (a != (b != c)); + foo (1 != 2 != c); // { dg-warning "comparison" "correct warning" } + foo ((1 != 2) != c); + foo (1 != (2 != c)); + foo (1 != 2 != 3); // { dg-warning "comparison" "correct warning" } + foo ((1 != 2) != 3); + foo (1 != (2 != 3)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-7.C b/gcc/testsuite/g++.dg/warn/Wparentheses-7.C new file mode 100644 index 000000000..7d549c38c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-7.C @@ -0,0 +1,83 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ copy of gcc.dg/Wparentheses-4.c + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a + b << c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) << c); + foo (a + (b << c)); + foo (1 + 2 << c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) << c); + foo (1 + (2 << c)); + foo (1 + 2 << 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) << 3); + foo (1 + (2 << 3)); + foo (a << b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a << b) + c); + foo (a << (b + c)); + foo (1 << 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 << 2) + c); + foo (1 << (2 + c)); + foo (1 << 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 << 2) + 3); + foo (1 << (2 + 3)); + foo (a + b >> c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) >> c); + foo (a + (b >> c)); + foo (1 + 2 >> c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) >> c); + foo (1 + (2 >> c)); + foo (1 + 2 >> 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) >> 3); + foo (1 + (2 >> 3)); + foo (a >> b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a >> b) + c); + foo (a >> (b + c)); + foo (1 >> 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 >> 2) + c); + foo (1 >> (2 + c)); + foo (1 >> 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 >> 2) + 3); + foo (1 >> (2 + 3)); + foo (a - b << c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) << c); + foo (a - (b << c)); + foo (6 - 5 << c); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) << c); + foo (6 - (5 << c)); + foo (6 - 5 << 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) << 4); + foo (6 - (5 << 4)); + foo (a << b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a << b) - c); + foo (a << (b - c)); + foo (6 << 5 - c); // { dg-warning "parentheses" "correct warning" } + foo ((6 << 5) - c); + foo (6 << (5 - c)); + foo (6 << 5 - 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 << 5) - 4); + foo (6 << (5 - 4)); + foo (a - b >> c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) >> c); + foo (a - (b >> c)); + foo (6 - 5 >> c); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) >> c); + foo (6 - (5 >> c)); + foo (6 - 5 >> 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 - 5) >> 4); + foo (6 - (5 >> 4)); + foo (a >> b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a >> b) - c); + foo (a >> (b - c)); + foo (6 >> 5 - c); // { dg-warning "parentheses" "correct warning" } + foo ((6 >> 5) - c); + foo (6 >> (5 - c)); + foo (6 >> 5 - 4); // { dg-warning "parentheses" "correct warning" } + foo ((6 >> 5) - 4); + foo (6 >> (5 - 4)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-8.C b/gcc/testsuite/g++.dg/warn/Wparentheses-8.C new file mode 100644 index 000000000..ddb5e64b4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-8.C @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-5.c + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a && b || c); // { dg-warning "parentheses" "correct warning" } + foo ((a && b) || c); + foo (a && (b || c)); + foo (1 && 2 || c); // { dg-warning "parentheses" "correct warning" } + foo ((1 && 2) || c); + foo (1 && (2 || c)); + foo (1 && 2 || 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 && 2) || 3); + foo (1 && (2 || 3)); + foo (a || b && c); // { dg-warning "parentheses" "correct warning" } + foo ((a || b) && c); + foo (a || (b && c)); + foo (1 || 2 && c); // { dg-warning "parentheses" "correct warning" } + foo ((1 || 2) && c); + foo (1 || (2 && c)); + foo (1 || 2 && 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 || 2) && 3); + foo (1 || (2 && 3)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-9.C b/gcc/testsuite/g++.dg/warn/Wparentheses-9.C new file mode 100644 index 000000000..bad6fb1c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-9.C @@ -0,0 +1,119 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +// C++ version of gcc.dg/Wparentheses-6.c + +int foo (int); + +int +bar (int a, int b, int c) +{ + foo (a & b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a & b) | c); + foo (a & (b | c)); + foo (1 & 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) | c); + foo (1 & (2 | c)); + foo (1 & 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 & 2) | 3); + foo (1 & (2 | 3)); + foo (a | b & c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) & c); + foo (a | (b & c)); + foo (1 | 2 & c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) & c); + foo (1 | (2 & c)); + foo (1 | 2 & 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) & 3); + foo (1 | (2 & 3)); + foo (a ^ b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a ^ b) | c); + foo (a ^ (b | c)); + foo (1 ^ 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) | c); + foo (1 ^ (2 | c)); + foo (1 ^ 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 ^ 2) | 3); + foo (1 ^ (2 | 3)); + foo (a | b ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) ^ c); + foo (a | (b ^ c)); + foo (1 | 2 ^ c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) ^ c); + foo (1 | (2 ^ c)); + foo (1 | 2 ^ 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) ^ 3); + foo (1 | (2 ^ 3)); + foo (a + b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a + b) | c); + foo (a + (b | c)); + foo (1 + 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) | c); + foo (1 + (2 | c)); + foo (1 + 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 + 2) | 3); + foo (1 + (2 | 3)); + foo (a | b + c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) + c); + foo (a | (b + c)); + foo (1 | 2 + c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) + c); + foo (1 | (2 + c)); + foo (1 | 2 + 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) + 3); + foo (1 | (2 + 3)); + foo (a - b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a - b) | c); + foo (a - (b | c)); + foo (1 - 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) | c); + foo (1 - (2 | c)); + foo (1 - 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 - 2) | 3); + foo (1 - (2 | 3)); + foo (a | b - c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) - c); + foo (a | (b - c)); + foo (1 | 2 - c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) - c); + foo (1 | (2 - c)); + foo (1 | 2 - 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) - 3); + foo (1 | (2 - 3)); + foo (a > b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a > b) | c); + foo (a > (b | c)); + foo (1 > 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 > 2) | c); + foo (1 > (2 | c)); + foo (1 > 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 > 2) | 3); + foo (1 > (2 | 3)); + foo (a | b > c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) > c); + foo (a | (b > c)); + foo (1 | 2 > c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) > c); + foo (1 | (2 > c)); + foo (1 | 2 > 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) > 3); + foo (1 | (2 > 3)); + foo (a <= b | c); // { dg-warning "parentheses" "correct warning" } + foo ((a <= b) | c); + foo (a <= (b | c)); + foo (1 <= 2 | c); // { dg-warning "parentheses" "correct warning" } + foo ((1 <= 2) | c); + foo (1 <= (2 | c)); + foo (1 <= 2 | 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 <= 2) | 3); + foo (1 <= (2 | 3)); + foo (a | b <= c); // { dg-warning "parentheses" "correct warning" } + foo ((a | b) <= c); + foo (a | (b <= c)); + foo (1 | 2 <= c); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) <= c); + foo (1 | (2 <= c)); + foo (1 | 2 <= 3); // { dg-warning "parentheses" "correct warning" } + foo ((1 | 2) <= 3); + foo (1 | (2 <= 3)); +} diff --git a/gcc/testsuite/g++.dg/warn/Wreorder-1.C b/gcc/testsuite/g++.dg/warn/Wreorder-1.C new file mode 100644 index 000000000..940ef4a46 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreorder-1.C @@ -0,0 +1,14 @@ +// { dg-options "-Wreorder -W" } + +struct S { + S (); +}; + +struct T { + T (); +}; + +struct U : virtual public S, virtual public T { + U () : T (), S () {} // { dg-warning "" } + U (const U&) : S () {} +}; diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-1.C b/gcc/testsuite/g++.dg/warn/Wreturn-1.C new file mode 100644 index 000000000..f0dba504b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-1.C @@ -0,0 +1,9 @@ +// { dg-options "-Wreturn-type" } +// PR c++/15742 + +extern void exit(int) __attribute__ ((noreturn)); + +template +struct A { + int find_cmp(void) { exit(1); } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-2.C b/gcc/testsuite/g++.dg/warn/Wreturn-2.C new file mode 100644 index 000000000..460afd53a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-2.C @@ -0,0 +1,7 @@ +// { dg-do compile } +int foo(int first) { + while (true) { + return first; + } +} // { dg-bogus "control reaches" } + diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-3.C b/gcc/testsuite/g++.dg/warn/Wreturn-3.C new file mode 100644 index 000000000..822dd4fdd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-3.C @@ -0,0 +1,18 @@ +// { dg-options "-Wreturn-type" } +// PR c++/20624 + +struct fpos { + fpos(int __pos) {} +}; +struct g { + g(); + ~g(); +}; +fpos seekoff(int b, int c) +{ + g __buf; + if (b != -1 && c >= 0) + return fpos(-1); + else + return fpos(-1); +} diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-1.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-1.C new file mode 100644 index 000000000..fb9a86291 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-1.C @@ -0,0 +1,11 @@ +// PR c++/11725 +// { dg-options "-Wreturn-type" } + +template +struct A +{ + int foo() + { + throw "Stop"; + } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-2.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-2.C new file mode 100644 index 000000000..ad59d4ec3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-2.C @@ -0,0 +1,20 @@ +// PR middle-end/16558 +// { dg-options "-Wreturn-type" } + +struct C +{ + C (); + ~C (); +}; + +int getref (int ndx) +{ + C d; + + if (ndx != 0) { + C base; + return 0; + } + else + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-3.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-3.C new file mode 100644 index 000000000..f13d58745 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-3.C @@ -0,0 +1,14 @@ +// PR middle-end/19583 +// { dg-options "-Wreturn-type -O" } + +struct E{}; + +inline int bar() throw(E) +{ + return 0; +} + +void foo () +{ + bar(); +} diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C new file mode 100644 index 000000000..4f02678e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C @@ -0,0 +1,43 @@ +/* PR c++/18313 */ +/* { dg-do compile } */ +/* { dg-options "-Wignored-qualifiers" } */ + +volatile void bar(); /* { dg-warning "type qualifiers ignored" } */ + +struct A +{ + const int bla(); /* { dg-warning "type qualifiers ignored" } */ + static const A getA(); /* { dg-bogus "type qualifiers" } */ +}; + +template const T getfoo(const T def) /* { dg-bogus "type qualifiers ignored" } */ +{ return def; } + +template class Pair +{ + public: + T getLeft() const { return T(); } /* { dg-bogus "type qualifiers ignored" } */ + const T getRight() const { return T(); } /* { dg-bogus "type qualifiers ignored" } */ +}; + +template struct S { + const int f(); /* { dg-warning "type qualifiers ignored" } */ + const T g(); /* { dg-bogus "type qualifiers ignored" } */ + T h(); +}; + +int* testtemplate() +{ + int i; + + Pair a; + + a.getLeft(); + a.getRight(); + + S b; + b.h(); /* { dg-bogus "type qualifiers ignored" } */ + b.g(); /* { dg-bogus "type qualifiers ignored" } */ + + return getfoo(&i); +} diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-5.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-5.C new file mode 100644 index 000000000..8a19d646f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-5.C @@ -0,0 +1,21 @@ +// PR c++/36254 +// { dg-do compile } +// { dg-options "-Wreturn-type" } + +int i, j, k; +struct X { X (); ~X (); }; + +bool +foo () +{ + X x; + if (i && j) + { + if (k) + return true; + else + return false; + } + else + return false; +} diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-6.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-6.C new file mode 100644 index 000000000..45ec95236 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-6.C @@ -0,0 +1,13 @@ +/* PR c++/40749 */ +/* { dg-do compile } */ +/* { dg-options "-Wreturn-type" } */ + +struct A {}; +const A a() {} /* { dg-warning "no return statement" } */ +const A& b() {} /* { dg-warning "no return statement" } */ + +const int c() {} /* { dg-warning "no return statement" } */ + +template +const int foo(T t) {} /* { dg-warning "no return statement" } */ +int d = foo(0), e = foo(1); diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-1.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-1.C new file mode 100644 index 000000000..fb5b8a1a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsequence-point-1.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// { dg-options "-Wsequence-point" } +struct C +{ + ~C() throw(); +}; + +void t_test1 (C* mapping) +{ + delete [] mapping; +} diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-2.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-2.C new file mode 100644 index 000000000..ab9c97a80 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsequence-point-2.C @@ -0,0 +1,28 @@ +// PR c++/45894 +// { dg-do compile } +// { dg-options "-std=c++0x -Wsequence-point" } + +struct F +{ + template + void bar (); +}; +template +struct V +{ + V (const V &) { F::bar <>; } +}; +struct C +{ + V <> v; +}; +struct B +{ + C f (); +}; +struct A +{ + C c; + B b; + A () : c (b.f ()) { } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-3.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-3.C new file mode 100644 index 000000000..5f73ca18b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsequence-point-3.C @@ -0,0 +1,20 @@ +// PR c++/46401 +// { dg-do compile } +// { dg-options "-Wsequence-point" } + +struct S +{ + S (); + S &operator<< (const char *); + S (const S &); +}; + +#define N1(n) << #n +#define N2(n) N1(n) +#define N3(n) N2(n##0) N2(n##1) N2(n##2) N2(n##3) N2(n##4) \ + N2(n##5) N2(n##6) N2(n##7) N2(n##8) N2(n##9) +#define N4(n) N3(n##0) N3(n##1) N3(n##2) N3(n##3) N3(n##4) \ + N3(n##5) N3(n##6) N3(n##7) N3(n##8) N3(n##9) +#define N5(n) N4(n##0) N4(n##1) N4(n##2) N4(n##3) N4(n##4) \ + N4(n##5) N4(n##6) N4(n##7) N4(n##8) N4(n##9) +S s = S () N5(a) N5(b); diff --git a/gcc/testsuite/g++.dg/warn/Wsequence-point-pr18050.C b/gcc/testsuite/g++.dg/warn/Wsequence-point-pr18050.C new file mode 100644 index 000000000..63aecd0f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsequence-point-pr18050.C @@ -0,0 +1,24 @@ +/* PR 18050 : bogus warning with -Wsequence-point */ +/* { dg-do compile } */ +/* { dg-options "-Wsequence-point" } */ + +struct x +{ + int i; +}; +void bar(struct x*, int *); + +void foo(struct x *y) +{ + bar(y++, &y->i); /* { dg-warning "operation on 'y' may be undefined" } */ +} + +void zz(int a, int *b) +{ + *b = a; +} + +void baz(void) { + int a = 5; + zz(++a, &a); /* { dg-bogus "operation on 'a' may be undefined" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-1.C b/gcc/testsuite/g++.dg/warn/Wshadow-1.C new file mode 100644 index 000000000..1647a010d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-1.C @@ -0,0 +1,41 @@ +/* Copyright (C) 2001, 2002 Free Software Foundation, Inc. */ + +/* { dg-do compile } */ +/* { dg-options -Wshadow } */ + +/* Source: Neil Booth, 3 Nov 2001, and PR 16, 713. -Wshadow was + giving a bunch of warnings we didn't want, and wasn't giving the + location of the shadowed variable. */ + +struct status // { dg-bogus "shadowed declaration" } +{ + int member; + void foo2 (); + + inline static int foo3 (int member) // { dg-bogus "shadows" } + { + return member; + } +}; + +int decl1; // { dg-warning "shadowed declaration" } +int decl2; // { dg-warning "shadowed declaration" } +void foo (struct status &status,// { dg-bogus "shadows a global decl" } + double decl1) // { dg-warning "shadows a global decl" } +{ +} + +void foo1 (int d) +{ + double d; // { dg-error "shadows a parameter" } +} + +void status::foo2 () +{ + int member; // { dg-warning "shadows a member" } + int decl2; // { dg-warning "shadows a global decl" } + int local; // { dg-warning "shadowed declaration" } + { + int local; // { dg-warning "shadows a previous local" } + } +} diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-2.C b/gcc/testsuite/g++.dg/warn/Wshadow-2.C new file mode 100644 index 000000000..a3e9428b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-2.C @@ -0,0 +1,10 @@ +/* { dg-options "-Wshadow" } */ + +struct A { + void a1 () { + struct B { B() {} }; // There should be no warning here. + } + void a2 () { + struct B { }; + } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-3.C b/gcc/testsuite/g++.dg/warn/Wshadow-3.C new file mode 100644 index 000000000..99add19a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-3.C @@ -0,0 +1,8 @@ +// PR c++/18530 +// { dg-options "-Wshadow" } + +struct A { + A(); + ~A(); + void foo (int __ct, int __dt) {} +}; diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-4.C b/gcc/testsuite/g++.dg/warn/Wshadow-4.C new file mode 100644 index 000000000..c033028d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-4.C @@ -0,0 +1,32 @@ +// PR c++/39526 +// { dg-options "-Wshadow" } + +class INetURLObject +{ +public: + INetURLObject(int i); + int GetMainURL() const; +}; + +int foo(int infoo) // { dg-bogus "shadowed declaration" } +{ + int outfoo( INetURLObject( infoo ).GetMainURL()); // { dg-bogus "shadows" } + extern void f(int infoo); + struct A + { + void f(int infoo) { } // { dg-bogus "shadows a parameter" } + }; + return outfoo; +} + +// PR c++/39763 +int foo2(void) +{ + int infoo = 0; // { dg-bogus "shadowed declaration" } + int outfoo( INetURLObject( infoo ).GetMainURL()); // { dg-bogus "shadows" } + struct A + { + void f(int infoo) { } // { dg-bogus "shadows a previous local" } + }; + return outfoo; +} diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-5.C b/gcc/testsuite/g++.dg/warn/Wshadow-5.C new file mode 100644 index 000000000..66232913f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-5.C @@ -0,0 +1,33 @@ +// Wshadows was giving warnings for nested function parameters in nested class +// or structure that we didn't want. +// { dg-do compile } +// { dg-options "-Wshadow" } + +// PR c++/41825 +int f (int n) +{ + int bar (int n) { return n++; } // { dg-error "a function-definition is not allowed here" } + return bar (n); // { dg-error "was not declared in this scope" } +} + +int g (int i) +{ + struct { + int bar (int i) { return i++; } // { dg-bogus "shadows" } + } s; + + return s.bar (i); +} + +// PR c++/30566 +void h( int x ) +{ + class InnerClass + { + public: + static int g( int x ) // { dg-bogus "shadows" } + { + // empty + } + }; +} diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-6.C b/gcc/testsuite/g++.dg/warn/Wshadow-6.C new file mode 100644 index 000000000..9b13e3ae7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-6.C @@ -0,0 +1,39 @@ +// Test the declaration of nested lambda function shadows +// a parameter or previous local. +// { dg-do compile } +// { dg-options "-std=c++0x -Wshadow" } + +struct S {}; +int f1(int x) // { dg-warning "shadowed declaration" } +{ + int t = 0; + int m = 0; // { dg-warning "shadowed declaration" } + [&t] (int x) { // { dg-warning "shadows a parameter" } + int m = 1; // { dg-warning "shadows a previous local" } + t = t + x + m; + }; + return t; +} + +void f2(struct S i, int j) { + struct A { + struct S x; + void g(struct S i) { // { dg-warning "shadowed declaration" } + struct S x; // { dg-warning "shadows a member of" } + struct S y; // { dg-warning "shadowed declaration" } + int t; + [&t](struct S i){ // { dg-warning "shadows a parameter" } + int j = 1; // { dg-bogus "shadows" } + struct S y; // { dg-warning "shadows a previous local" } + t = j; + }; + } + }; +} + +void f3(int i) { + [=]{ + int j = i; + int i; // { dg-warning "shadows a member of" } + }; +} diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-7.C b/gcc/testsuite/g++.dg/warn/Wshadow-7.C new file mode 100644 index 000000000..5de952ee7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wshadow-7.C @@ -0,0 +1,37 @@ +// PR c++/44128 +// { dg-options "-Wshadow" } + +typedef long My_ssize_t; // { dg-warning "shadowed declaration" } +typedef int Foo; // { dg-warning "shadowed declaration" } +struct Bar1 { // { dg-bogus "shadowed declaration" } + int a; +}; +struct Bar2 { // { dg-warning "shadowed declaration" } + int a; +}; + +void func() { + typedef int My_ssize_t; // { dg-warning "shadows a global" } + typedef char My_Num; // { dg-warning "shadowed declaration" } + { + typedef short My_Num; // { dg-warning "shadows a previous local" } + } + int Foo; // { dg-warning "shadows a global" } + float Bar1; // { dg-bogus "shadows a global" } + struct Bar2 { // { dg-warning "shadows a global" } + int a; + }; + struct Bar3 { // { dg-warning "shadowed declaration" } + int a; + }; + struct Bar4 { // { dg-bogus "shadowed declaration" } + int a; + }; + { + struct Bar3 { // { dg-warning "shadows a previous local" } + int a; + }; + char Bar4; // { dg-bogus "shadows a previous local" } + int My_Num; // { dg-warning "shadows a previous local" } + } +} diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-1.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-1.C new file mode 100644 index 000000000..495bb992c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-1.C @@ -0,0 +1,6 @@ +// { dg-options "-Wsign-compare" } + +extern unsigned u; + +template +int f() { return u > 1; } diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C new file mode 100644 index 000000000..2b8360648 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-2.C @@ -0,0 +1,10 @@ +// PR c/35430 +// { dg-do compile } +// { dg-options "-Wsign-compare" } + +void +foo (__complex__ int i) +{ + i == 0u; + i == ~1u; // { dg-warning "comparison between signed and unsigned integer expressions" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wsign-compare-3.C b/gcc/testsuite/g++.dg/warn/Wsign-compare-3.C new file mode 100644 index 000000000..dc42f41a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-compare-3.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-Wsign-compare" } + +enum E { A, B, C }; +extern void f1(int); +void +f2(E v1, E v2) +{ + for (unsigned int i = v1; i <= v2; ++i) + f1(i); + for (int i = v1; i <= v2; ++i) + f1(i); +} diff --git a/gcc/testsuite/g++.dg/warn/Wsign-conversion.C b/gcc/testsuite/g++.dg/warn/Wsign-conversion.C new file mode 100644 index 000000000..83fe2ed66 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-conversion.C @@ -0,0 +1,95 @@ +/* Test for diagnostics for implicit conversions between signed and + unsigned integer types. + C++ equivalent of gcc/testsuite/gcc.dg/Wsign-conversion.c */ + +// { dg-do compile } +// { dg-options "-fsigned-char -Wsign-conversion" } +#include + +void fsc (signed char sc); +void fuc (unsigned char uc); +unsigned fui (unsigned int ui); +void fsi (signed int ui); + +void h (int x) +{ + unsigned int ui = 3; + int si = 3; + unsigned char uc = 3; + signed char sc = 3; + + uc = ui; + uc = si; + sc = ui; + sc = si; + fuc (ui); + fuc (si); + fsc (ui); + fsc (si); + + fsi (si); + fui (ui); + fsi (uc); + si = uc; + fui (uc); + ui = uc; + fui ('A'); + ui = 'A'; + fsi ('A'); + si = 'A'; + fuc ('A'); + uc = 'A'; + + uc = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = x ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + + fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */ + ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + fsi (0x80000000); /* { dg-warning "conversion" } */ + si = 0x80000000; /* { dg-warning "conversion" } */ + + + fsi (UINT_MAX - 1); /* { dg-warning "conversion" } */ + si = UINT_MAX - 1; /* { dg-warning "conversion" } */ + fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */ + si = UINT_MAX - 1U; /* { dg-warning "conversion" } */ + fsi (UINT_MAX/3U); + si = UINT_MAX/3U; + fsi (UINT_MAX/3); + si = UINT_MAX/3; + fui (UINT_MAX - 1); + ui = UINT_MAX - 1; + + uc = (unsigned char) -1; + ui = -1 * (1 * -1); + ui = (unsigned) -1; + + fsc (uc); /* { dg-warning "conversion" } */ + sc = uc; /* { dg-warning "conversion" } */ + fuc (sc); /* { dg-warning "conversion" } */ + uc = sc; /* { dg-warning "conversion" } */ + fsi (ui); /* { dg-warning "conversion" } */ + si = ui; /* { dg-warning "conversion" } */ + fui (si); /* { dg-warning "conversion" } */ + ui = si; /* { dg-warning "conversion" } */ + fui (sc); /* { dg-warning "conversion" } */ + ui = sc; /* { dg-warning "conversion" } */ +} + +unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */ + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-1.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-1.C new file mode 100644 index 000000000..3e9db3611 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-1.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +double x; +int *foo(void) +{ + return (int *)&x; /* { dg-warning "strict-aliasing" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-2.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-2.C new file mode 100644 index 000000000..713b35461 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-2.C @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +double x; + +template +T *foo(void) +{ + return (T *)&x; /* { dg-bogus "strict-aliasing" } */ +} + +template double *foo(void); + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-3.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-3.C new file mode 100644 index 000000000..94c2f4702 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-3.C @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +double x; + +template +T *foo(void) +{ + return (T *)&x; /* { dg-warning "strict-aliasing" } */ +} + +template int *foo(void); /* { dg-message "instantiated from here" } */ +template char *foo(void); /* { dg-bogus "instantiated from here" } */ + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-4.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-4.C new file mode 100644 index 000000000..e877c70fb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-4.C @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +double x; + +template +T *foo(void) +{ + int a[2]; + float *y = (float *)a; /* { dg-bogus "strict-aliasing" } */ + return (T *)&x; /* { dg-bogus "strict-aliasing" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-5.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-5.C new file mode 100644 index 000000000..a04925118 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-5.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +float foo () +{ + unsigned int MASK = 0x80000000; + return (float &) MASK; /* { dg-warning "strict-aliasing" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C new file mode 100644 index 000000000..6f935c854 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +int foo () +{ + char buf[8]; + return *((int *)buf); /* { dg-warning "strict-aliasing" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C new file mode 100644 index 000000000..71ed6cae8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-7.C @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2" } */ + +int a[2]; + +double *foo1(void) +{ + return (double *)a; /* { dg-warning "strict-aliasing" } */ +} + +double *foo2(void) +{ + return (double *)&a[0]; /* { dg-warning "strict-aliasing" } */ +} + +__complex__ double x; +int *bar(void) +{ + return (int *)&__imag__ x; /* { dg-warning "strict-aliasing" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C new file mode 100644 index 000000000..497565eec --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-8.C @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=2 -O2 -Wall" } */ + +int a[2]; + +double *foo1(void) +{ + return (double *)a; /* { dg-warning "strict-aliasing" } */ +} + +double *foo2(void) +{ + return (double *)&a[0]; /* { dg-warning "strict-aliasing" } */ +} + +__complex__ double x; +int *bar(void) +{ + return (int *)&__imag__ x; /* { dg-warning "strict-aliasing" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-base-derived.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-base-derived.C new file mode 100644 index 000000000..18e6caf90 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-base-derived.C @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +class base { + public: + int x; +}; + +class derived: public base { + public: + int y; +}; + +base foo () { + derived d; + base* pb = &d; /* { dg-bogus "base vs. derived" } */ + pb->x = 1; + + return d; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-1.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-1.C new file mode 100644 index 000000000..bdd24aca6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-1.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +int foo () { + int i; + char* c= reinterpret_cast(&i); /* { dg-bogus "char" } */ + c[1] = 1; + return i; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-const.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-const.C new file mode 100644 index 000000000..7c079ad5c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-const.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + +int foo(int* p) { + const int& q = *p; /* { dg-bogus "const vs. non-const" } */ + *p = 1; + return q; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C new file mode 100644 index 000000000..29414e00e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-2.C @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing" } */ + +#include + +struct A +{ + virtual ~A(); +}; + +A* foo(); + +void bar(std::list x) +{ + std::list y = x; + if (*y.rbegin()) + delete foo(); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C new file mode 100644 index 000000000..de6b2c477 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape-3.C @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing" } */ + +struct Node_base {}; + +struct Node : Node_base +{ + int data; +}; + +struct List +{ + Node_base node, *prev; + + List() : prev(&node) { xyz(); } + + void xyz(); + + int back() { return static_cast(prev)->data; } +}; + +struct A +{ + virtual ~A(); +}; + +A* foo(); + +void bar() +{ + List y; + if (y.back()) + delete foo(); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape.C new file mode 100644 index 000000000..9ea619877 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-escape.C @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing" } */ + +#include +#include + +class A; + +class B { +public: + void foo(A&); + std::string s; +}; + +class A { +public: + A& qaz() { + l.push_back( new A() ); + return *l.back(); + } + std::list l; +}; + +void bar() +{ + A a; + B b; + b.foo(a.qaz()); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-nested-arrays.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-nested-arrays.C new file mode 100644 index 000000000..529118102 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-nested-arrays.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + +int foo () { + int buffer[10][10]; + int* pi = &buffer[0][0]; /* { dg-bogus "same element type" } */ + *pi = 10; + return buffer[0][0]; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-placement-new.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-placement-new.C new file mode 100644 index 000000000..514957bcd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-placement-new.C @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing" } */ + +inline void *operator new (__SIZE_TYPE__, void *__p) throw() { return __p; } + +struct Y { + Y() {} + int i; +}; + +struct X { + X() {} + void construct(const Y& y) + { + new (&m_data[0]) Y(y); + } + bool initialized; + char m_data[sizeof (Y)]; +}; + +void bar(const X&); +void foo(Y& y) +{ + X x; + x.construct(y); + x.initialized = true; + bar(x); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-signed-unsigned.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-signed-unsigned.C new file mode 100644 index 000000000..5e71ebff8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-signed-unsigned.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +int foo () { + int i; + unsigned int* pu = reinterpret_cast (&i); /* { dg-bogus "signed vs. unsigned" } */ + *pu = 1000000; + return i; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-struct-included.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-struct-included.C new file mode 100644 index 000000000..3f55c78c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-struct-included.C @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +struct S { + int i; + float f; +}; + +int foo () { + struct S s; + s.i = 7; + float* f = &s.f; /* { dg-bogus "float included in struct S" } */ + *f = 2.0; + return s.i + (int)s.f; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union.C new file mode 100644 index 000000000..dfbb42c6f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-union.C @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +union U { + int i; + float f; +}; + +float foo () { + union U u; + float* f = &u.f; /* { dg-bogus "unions are holy in GCC" } */ + u.i = 2; + return *f; +} diff --git a/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-float-ref-int-obj.C b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-float-ref-int-obj.C new file mode 100644 index 000000000..103248da4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstrict-aliasing-float-ref-int-obj.C @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wstrict-aliasing -fstrict-aliasing" } */ + + +int foo() { + int x; + float& q = reinterpret_cast (x); /* { dg-message "dereferencing type-punned" "" { target *-*-* } } */ + q = 1.0; /* { dg-warning "does break strict-aliasing" "" { xfail *-*-* } } */ + return x; +} + +/* { dg-message "initialized" "" { xfail *-*-* } 7 } */ diff --git a/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C new file mode 100644 index 000000000..97e317644 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-1.C @@ -0,0 +1,29 @@ +/* PR c/7776 */ +/* { dg-do compile } */ +/* { dg-options "-Waddress" } */ + +int test1(char *ptr) +{ + return ptr == "foo"; /* { dg-warning "comparison with string" } */ +} + +int test2() +{ + return "foo" != (const char*)0; +} + +int test3() +{ + return "foo" == (const char*)0; +} + +int test4() +{ + return (const char*)0 != "foo"; +} + +int test5() +{ + return (const char*)0 == "foo"; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-2.C b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-2.C new file mode 100644 index 000000000..3eb91eeca --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-2.C @@ -0,0 +1,29 @@ +/* PR c/7776 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +int test1(char *ptr) +{ + return ptr == "foo"; /* { dg-warning "comparison with string" } */ +} + +int test2() +{ + return "foo" != (const char*)0; +} + +int test3() +{ + return "foo" == (const char*)0; +} + +int test4() +{ + return (const char*)0 != "foo"; +} + +int test5() +{ + return (const char*)0 == "foo"; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-3.C b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-3.C new file mode 100644 index 000000000..f700a51a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-3.C @@ -0,0 +1,29 @@ +/* PR c/7776 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int test1(char *ptr) +{ + return ptr == "foo"; +} + +int test2() +{ + return "foo" != (const char*)0; +} + +int test3() +{ + return "foo" == (const char*)0; +} + +int test4() +{ + return (const char*)0 != "foo"; +} + +int test5() +{ + return (const char*)0 == "foo"; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C new file mode 100644 index 000000000..f2a711aeb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstring-literal-comparison-4.C @@ -0,0 +1,29 @@ +/* PR c/7776 */ +/* { dg-do compile } */ +/* { dg-options "-Wall -Wno-address" } */ + +int test1(char *ptr) +{ + return ptr == "foo"; +} + +int test2() +{ + return "foo" != (const char*)0; +} + +int test3() +{ + return "foo" == (const char*)0; +} + +int test4() +{ + return (const char*)0 != "foo"; +} + +int test5() +{ + return (const char*)0 == "foo"; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-1.C b/gcc/testsuite/g++.dg/warn/Wswitch-1.C new file mode 100644 index 000000000..1da7180ec --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-1.C @@ -0,0 +1,63 @@ +/* PR c/4475, PR c++/3780 */ +/* { dg-do compile } */ +/* { dg-options "-Wswitch" } */ + +enum e { e1, e2 }; + +int +foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el, + enum e em, enum e en, enum e eo, enum e ep) +{ + switch (i) + { + case 1: return 1; + case 2: return 2; + } + switch (j) + { + case 3: return 4; + case 4: return 3; + default: break; + } + switch (ei) /* { dg-warning "enumeration value 'e1' not handled in switch" "enum e1" } */ + { /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" { target *-*-* } 22 } */ + } + switch (ej) + { + default: break; + } + switch (ek) /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" } */ + { + case e1: return 1; + } + switch (el) + { + case e1: return 1; + default: break; + } + switch (em) + { + case e1: return 1; + case e2: return 2; + } + switch (en) + { + case e1: return 1; + case e2: return 2; + default: break; + } + switch (eo) + { + case e1: return 1; + case e2: return 2; + case 3: return 3; /* { dg-warning "case value" } */ + } + switch (ep) + { + case e1: return 1; + case e2: return 2; + case 3: return 3; /* { dg-warning "case value" } */ + default: break; + } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-2.C b/gcc/testsuite/g++.dg/warn/Wswitch-2.C new file mode 100644 index 000000000..79ba4bdcb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-2.C @@ -0,0 +1,31 @@ +/* Further -Wswitch tests. */ +/* { dg-do compile } */ +/* { dg-options "-Wswitch" } */ + +enum e { e1 = 0, e2 = 1, e3 = 1, e4 = 2 }; + +int +foo (enum e ei, int j) +{ + switch (ei) + { + case e1: return 1; + case e3: return 2; + case e4: return 3; + } /* No warning here since e2 has the same value as e3. */ + switch (ei) /* { dg-warning "enumeration value 'e4' not handled in switch" "enum e4" } */ + { + case e1: return 1; + case e2: return 2; + } + switch ((int) ei) + { + case e1: return 1; + } /* No warning here since switch condition was cast to int. */ + switch ((enum e) j) /* { dg-warning "enumeration value 'e1' not handled in switch" "enum e1" } */ + { + case e2: return 1; + case e4: return 2; + } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-3.C b/gcc/testsuite/g++.dg/warn/Wswitch-3.C new file mode 100644 index 000000000..df1f8956d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-3.C @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-Wswitch" } */ + +enum E { A, B, C, D, E, F }; + +int +f1 (enum E e) +{ + switch (e) + { + case A: return 1; + case B: return 2; + case C: return 3; + case D: return 4; + case E: return 5; + case F: return 6; + case 7: return 7; /* { dg-warning "not in enumerated type" } */ + } + return 0; +} + +int +f2 (enum E e) +{ + switch (e) + { + case A: return 1; + case B: return 2; + case C: return 3; + case D: return 4; + case E: return 5; + case F: return 6; + case 7: return 7; /* { dg-warning "not in enumerated type" } */ + default: return 8; + } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-default-1.C b/gcc/testsuite/g++.dg/warn/Wswitch-default-1.C new file mode 100644 index 000000000..2236ae531 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-default-1.C @@ -0,0 +1,22 @@ +// PR C++/21123 +/* { dg-do compile } */ +/* { dg-options "-Wswitch-default" } */ + + +template +void foo( ) +{ + int i = 0; + + switch ( i ) /* { dg-bogus "switch missing default case" } */ + { + case 9: + default: + break; + } +} + +void f() +{ + foo(); +} diff --git a/gcc/testsuite/g++.dg/warn/Wswitch-default-2.C b/gcc/testsuite/g++.dg/warn/Wswitch-default-2.C new file mode 100644 index 000000000..832f867e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wswitch-default-2.C @@ -0,0 +1,21 @@ +// PR C++/21123 +/* { dg-do compile } */ +/* { dg-options "-Wswitch-default" } */ + + +template +void foo( ) +{ + int i = 0; + + switch ( i ) /* { dg-warning "switch missing default case" } */ + { + case 9: + break; + } +} + +void f() +{ + foo(); +} diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C b/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C new file mode 100644 index 000000000..9cbdbe547 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C @@ -0,0 +1,84 @@ +/* Test that -Wtype-limits is enabled by -Wextra. */ +/* { dg-do compile } */ +/* { dg-options "-Wextra" } */ +extern void assert (int); + +void a (unsigned char x) +{ + if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */ + return; + if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */ + return; + if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */ + return; + if (255 >= (unsigned char) 1) + return; + +} + +void b (unsigned short x) +{ + if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ +} + +void c (unsigned int x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (1U >= 0) return; + if (1U < 0) return; + if (0 <= 1U) return; + if (0 > 1U) return; +} + +void d (unsigned long x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ +} + +void e (unsigned long long x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ +} + +int test (int x) +{ + if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */ + return 1; + else + return 0; +} + +template +void f(Int x) { + assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to limited range of data type" } +} + +int ff(void) { + f(5); + f(5); +} + +template +void g(void) { + assert(0 <= D); +} +int gg(void) { + g(); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C b/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C new file mode 100644 index 000000000..5040e2657 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C @@ -0,0 +1,84 @@ +/* Test disabling -Wtype-limits. */ +/* { dg-do compile } */ +/* { dg-options "-Wextra -Wno-type-limits" } */ +extern void assert (int); + +void a (unsigned char x) +{ + if (x < 0) return;/* { dg-bogus "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-bogus "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */ + if (x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" } */ + return; + if (255 >= x) /* { dg-bogus "comparison is always true due to limited range of data type" } */ + return; + if ((int)x <= 255) + return; + if (255 >= (unsigned char) 1) + return; + +} + +void b (unsigned short x) +{ + if (x < 0) return;/* { dg-bogus "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-bogus "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-bogus "comparison is always true due to limited range of data type" } */ +} + +void c (unsigned int x) +{ + if (x < 0) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ + if (1U >= 0) return; + if (1U < 0) return; + if (0 <= 1U) return; + if (0 > 1U) return; +} + +void d (unsigned long x) +{ + if (x < 0) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ +} + +void e (unsigned long long x) +{ + if (x < 0) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-bogus "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-bogus "comparison of unsigned expression >= 0 is always true" } */ +} + +int test (int x) +{ + if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" } */ + return 1; + else + return 0; +} + +template +void f(Int x) { + assert(0 <= x and x <= D); // { dg-bogus "comparison is always true due to limited range of data type" } +} + +int ff(void) { + f(5); + f(5); +} + +template +void g(void) { + assert(0 <= D); +} +int gg(void) { + g(); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits.C b/gcc/testsuite/g++.dg/warn/Wtype-limits.C new file mode 100644 index 000000000..814c2a882 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wtype-limits.C @@ -0,0 +1,84 @@ +/* { dg-do compile } */ +/* { dg-options "-Wtype-limits" } */ + +extern void assert (int); + +void a (unsigned char x) +{ + if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (x <= 255) /* { dg-warning "comparison is always true due to limited range of data type" } */ + return; + if (255 >= x) /* { dg-warning "comparison is always true due to limited range of data type" } */ + return; + if ((int)x <= 255) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 16 } */ + return; + if (255 >= (unsigned char) 1) + return; + +} + +void b (unsigned short x) +{ + if (x < 0) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (x >= 0) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ + if (0 > x) return;/* { dg-warning "comparison is always false due to limited range of data type" } */ + if (0 <= x) return;/* { dg-warning "comparison is always true due to limited range of data type" } */ +} + +void c (unsigned int x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (1U >= 0) return; + if (1U < 0) return; + if (0 <= 1U) return; + if (0 > 1U) return; +} + +void d (unsigned long x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ +} + +void e (unsigned long long x) +{ + if (x < 0) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (x >= 0) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ + if (0 > x) return;/* { dg-warning "comparison of unsigned expression < 0 is always false" } */ + if (0 <= x) return;/* { dg-warning "comparison of unsigned expression >= 0 is always true" } */ +} + +int test (int x) +{ + if ((long long)x <= 0x123456789ABCLL) /* { dg-bogus "comparison is always true due to limited range of data type" "" { xfail *-*-* } 61 } */ + return 1; + else + return 0; +} + +template +void f(Int x) { + assert(0 <= x and x <= D); // { dg-warning "comparison is always true due to limited range of data type" } +} + +int ff(void) { + f(5); + f(5); +} + +template +void g(void) { + assert(0 <= D); +} +int gg(void) { + g(); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C b/gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C new file mode 100644 index 000000000..0f6ccfd9d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitializable-member-no.C @@ -0,0 +1,15 @@ +// Test disabling +// { dg-do compile } +// { dg-options "-Wall -Wextra -Wno-uninitialized" } + +class X { + int & flag;// { dg-bogus "non-static reference 'int& X::flag' in class without a constructor" } +public: + void f(){ flag++ ; } +}; + +class Y { + const int var;// { dg-bogus "non-static const member 'const int Y::var' in class without a constructor" } +public: + int g(){ return 2*var; } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wuninitializable-member.C b/gcc/testsuite/g++.dg/warn/Wuninitializable-member.C new file mode 100644 index 000000000..1c37e3ea0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitializable-member.C @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-options "-Wuninitialized" } + +class X { + int & flag;// { dg-warning "non-static reference 'int& X::flag' in class without a constructor" } +public: + void f(){ flag++ ; } +}; + +class Y { + const int var;// { dg-warning "non-static const member 'const int Y::var' in class without a constructor" } +public: + int g(){ return 2*var; } +}; diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-1.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-1.C new file mode 100644 index 000000000..7b1b90b94 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-1.C @@ -0,0 +1,15 @@ +/* { dg-options "-O2 -Wuninitialized" } */ + +struct Empty { Empty() {} }; /* { dg-bogus "uninitialized" } */ +struct Other { + Other(const Empty& e_) : e(e_) {} + Empty e; +}; +void bar(Other&); +void foo() +{ + Empty e; + Other o(e); + bar(o); +} + diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-2.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-2.C new file mode 100644 index 000000000..2b6f92530 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-2.C @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +struct S8 { template S8(T) { } }; + +template struct S10; +template struct S10 { typedef T S12; typedef S8 S1(); }; + +template struct S3 { }; +template struct S11 { S11(S3); }; + +struct S2 +{ + template operator S11() { return S11(S5()); } + template struct S5:public S3 + { + virtual typename S10::S12 S13() { + return 0; + } + }; +}; + +template S11 S6(S3) { return S11(S3()); } +template struct S7 { typedef S12 S15(); }; + +struct S4 +{ + template operator S11() + { + struct S14:public S3 + { + S14(S2 x):S11_(x) { } + S11::S12>::S15> S11_; + }; + return S6(S14(S11_)); + } + S2 S11_; +}; + +struct S9 +{ + template operator S11() { return S11(S14(S11_)); } + template struct S14:public S3 + { + S14(S4 x):S11_(x) { } + S11::S1> S11_; + }; + S4 S11_; +}; + +void S15(S11); +void S16() { S9 x; S15(x); } + diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C new file mode 100644 index 000000000..dc3be3f67 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-3.C @@ -0,0 +1,17 @@ +// PR C++/38908 +// { dg-options "-Wuninitialized -O" } + +struct empty {}; + +struct dfs_visitor { + dfs_visitor() { } + empty m_vis; +}; + +void bar(const dfs_visitor&); +void foo(void) +{ + dfs_visitor vis; + dfs_visitor vis2 = vis; + bar (vis2); +} diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-4.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-4.C new file mode 100644 index 000000000..3d2543fb1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-4.C @@ -0,0 +1,22 @@ +// PR middle-end/39666 +// { dg-do compile } +// { dg-options "-O2 -Wuninitialized" } + +int +foo (int i) +{ + int j; + switch (i) + { + case -__INT_MAX__ - 1 ... -1: + j = 6; + break; + case 0: + j = 5; + break; + case 1 ... __INT_MAX__: + j = 4; + break; + } + return j; +} diff --git a/gcc/testsuite/g++.dg/warn/Wuninitialized-5.C b/gcc/testsuite/g++.dg/warn/Wuninitialized-5.C new file mode 100644 index 000000000..787d3c78f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wuninitialized-5.C @@ -0,0 +1,22 @@ +// PR middle-end/39666 +// { dg-do compile } +// { dg-options "-O2 -Wuninitialized" } + +int +foo (int i) +{ + int j; + switch (i) + { + case -__INT_MAX__ - 1 ... -1: + j = 6; + break; + case 0: + j = 5; + break; + case 2 ... __INT_MAX__: + j = 4; + break; + } + return j; // { dg-warning "may be used uninitialized" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C b/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C new file mode 100644 index 000000000..23fc86dfb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunreachable-code-1.C @@ -0,0 +1,22 @@ +/* PR17544 Incorrect -Wunreachable-code warning + Origin: sebor@roguewave.com + + G++ appends a "return 0;" when finishing a function, but it was not + given a source location. The gimplifier thinks a return statement + needs a locus so it would add one, making the compiler generated code + visible to the unreachable code warning. */ + +/* { dg-do compile } */ +/* { dg-options "-O -Wunreachable-code" } */ + +int +main (int argc, char *argv[]) +{ + const char* const s = argc < 2 ? "" : argv [1]; + int i = 0; + do { + ++i; + } while (i < s [0]); + return i; +} + diff --git a/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C b/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C new file mode 100644 index 000000000..d50f7fe57 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunreachable-code-2.C @@ -0,0 +1,23 @@ +// PR c++/21228 +/* { dg-options "-Wunreachable-code" } */ + +class testStringBase +{ +public: + char *stringPtr; +}; + +class testString : public testStringBase +{ +public: + testString(); +}; + +testString::testString() +{ + stringPtr = (char *) 9; +} + +int main(int argc, char **argv) { + testString s; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-1.C b/gcc/testsuite/g++.dg/warn/Wunused-1.C new file mode 100644 index 000000000..60ceb4f07 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-1.C @@ -0,0 +1,15 @@ +// Test whether -Wunused handles empty classes the same as non-empty. +// { dg-do compile } +// { dg-options "-Wunused" } + +struct A {}; +struct B { char c; }; + +void foo () +{ + struct A a0, a1; + struct B b0, b1 = { 25 }; + + a0 = a1; // { dg-bogus "value computed is not used" } + b0 = b1; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-10.C b/gcc/testsuite/g++.dg/warn/Wunused-10.C new file mode 100644 index 000000000..d2d6a343d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-10.C @@ -0,0 +1,8 @@ +// PR c++/19190 +// { dg-options "-Wunused" } + +struct breakme +{ + void setAction( unsigned char a ) { act = a; } + unsigned int act:8; +}; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-11.C b/gcc/testsuite/g++.dg/warn/Wunused-11.C new file mode 100644 index 000000000..4a151d245 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-11.C @@ -0,0 +1,11 @@ +// PR c++/20212 +// { dg-options "-O2 -Wunused -Wextra" } + +template void f(int); +void g(int i) +{ + f<0>(i); +} +template void f(int i __attribute__((unused)) ) +{} + diff --git a/gcc/testsuite/g++.dg/warn/Wunused-12.C b/gcc/testsuite/g++.dg/warn/Wunused-12.C new file mode 100644 index 000000000..51d234331 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-12.C @@ -0,0 +1,8 @@ +// PR c++/24302 +// { dg-options "-Wunused" } + +static union +{ + unsigned char FLT4ARR[4]; + float FLT4; +}; // { dg-warning "used" } diff --git a/gcc/testsuite/g++.dg/warn/Wunused-13.C b/gcc/testsuite/g++.dg/warn/Wunused-13.C new file mode 100644 index 000000000..d0eae113e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-13.C @@ -0,0 +1,7 @@ +// Test whether -Wunused handles effectless indirect_ref operation ('*'). +// { dg-do compile } +// { dg-options "-Wunused" } + +void Foo(int* x) { + *x++; // { dg-warning "value computed is not used" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-14.C b/gcc/testsuite/g++.dg/warn/Wunused-14.C new file mode 100644 index 000000000..b325ccb71 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-14.C @@ -0,0 +1,14 @@ +// Test that -Wunused should not emit a warning on the initialization of +// non-POD arrays. See PR c++/39803. +// { dg-do compile } +// { dg-options "-Wunused" } + +#include + +using std::pair; + +int foo() { + pair components[3]; // { dg-bogus "value computed is not used" } + components[0].first = 0; + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-15.C b/gcc/testsuite/g++.dg/warn/Wunused-15.C new file mode 100644 index 000000000..efaebc006 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-15.C @@ -0,0 +1,11 @@ +// PR c++/39875 +// { dg-do compile } +// { dg-options "-Wunused-value" } + +int *i; +void +foo () +{ + *i++; // { dg-warning "value computed is not used" } + (void) *i++; // { dg-bogus "value computed is not used" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-16.C b/gcc/testsuite/g++.dg/warn/Wunused-16.C new file mode 100644 index 000000000..c9e57f79b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-16.C @@ -0,0 +1,9 @@ +// { dg-do compile } +// { dg-options "-Wunused-value" } + +extern void f1(); +void +f(bool b) +{ + b ? f1(), 0 : 0; // { dg-bogus "has no effect" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-17.C b/gcc/testsuite/g++.dg/warn/Wunused-17.C new file mode 100644 index 000000000..217bb4b77 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-17.C @@ -0,0 +1,19 @@ +// PR c++/41109, 41110, 41134 +// { dg-options "-Wunused" } + +int memory_consumption(const int &t) { return sizeof(t); } + +int s; +int g() { return memory_consumption(s); } + +template struct X { static const int s = 2; }; + +template int f() { + const unsigned int dim = 2; + return X::s; +} + +template int f(); + +static int i; +template int h() { return i; } diff --git a/gcc/testsuite/g++.dg/warn/Wunused-2.C b/gcc/testsuite/g++.dg/warn/Wunused-2.C new file mode 100644 index 000000000..593bf4872 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-2.C @@ -0,0 +1,6 @@ +// { dg-do compile } +// { dg-options "-Wunused -O3" } + +static const int i = 0; +static void f() { } /* { dg-warning "defined but not used" "" } */ +static inline void g() { } diff --git a/gcc/testsuite/g++.dg/warn/Wunused-3.C b/gcc/testsuite/g++.dg/warn/Wunused-3.C new file mode 100644 index 000000000..310090943 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-3.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// { dg-options "-Wunused -O" } + +void do_cleanups(); + +class Cleanup { +public: + ~Cleanup() { do_cleanups();} +}; + +static Cleanup dummy; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-4.C b/gcc/testsuite/g++.dg/warn/Wunused-4.C new file mode 100644 index 000000000..9018e92ef --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-4.C @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-options "-Wunused-parameter" } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Sep 2003 +// Origin: yotamm@mellanox.co.il + + +// PR c++/9848. Missing warning + +struct C1 { + // Only use in-charge ctor + C1(int bi) {} // { dg-warning "unused parameter" "" } +}; +struct C2 { + // Only use base ctor + C2(int bi) {} // { dg-warning "unused parameter" "" } +}; + +struct D : C2 +{ + D (int) : C2 (1) {} +}; + +void show_compile_warning () +{ + C1 c1 (1); + + D d (1); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-5.C b/gcc/testsuite/g++.dg/warn/Wunused-5.C new file mode 100644 index 000000000..8a8d9d280 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-5.C @@ -0,0 +1,19 @@ +/* PR opt/14288 */ +/* { dg-do compile } */ +/* { dg-options "-O -Wall" } */ + +volatile int sink; +extern int foo(int); + +struct S +{ + int x; + + S() { x = foo(0); } + ~S() { sink = x; } +}; + +int test(bool p) +{ + return p ? foo(S().x) : 0; /* { dg-bogus "uninitialized" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-6.C b/gcc/testsuite/g++.dg/warn/Wunused-6.C new file mode 100644 index 000000000..58a3f642b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-6.C @@ -0,0 +1,11 @@ +/* PR middle-end/14203 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void foo() +{ + if (false) + if (int i=0) // { dg-warning "unused" "" } + int j=0; // { dg-warning "unused" "" } +} + diff --git a/gcc/testsuite/g++.dg/warn/Wunused-7.C b/gcc/testsuite/g++.dg/warn/Wunused-7.C new file mode 100644 index 000000000..6f5c23e95 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-7.C @@ -0,0 +1,12 @@ +// PR c++/14481 +// { dg-options "-Wunused" } + +void func() +{ + struct mybitfields { + unsigned int s_field:8; + }; + struct mybitfields s; // { dg-warning "set but not used" } + s.s_field = 255; +}; + diff --git a/gcc/testsuite/g++.dg/warn/Wunused-8.C b/gcc/testsuite/g++.dg/warn/Wunused-8.C new file mode 100644 index 000000000..a1c8a1fb4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-8.C @@ -0,0 +1,9 @@ +// PR c++/16029 +// { dg-options "-Wunused" } + +int main () +{ + // We should not see an "unused" warning about "whatever" on the + // next line. + return whatever (); // { dg-error "declared" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-9.C b/gcc/testsuite/g++.dg/warn/Wunused-9.C new file mode 100644 index 000000000..869888955 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-9.C @@ -0,0 +1,38 @@ +// PR c++/11224 +// { dg-options "-Wunused" } + +struct someclass { + + bool isEmpty() const { return true; } +}; + +int main() +{ + bool bOk = false; + someclass foo; + + bOk == foo.isEmpty(); // { dg-warning "not used" } + + return bOk; +} + +int& f(); + +void g() { + f() == 0; // { dg-warning "not used" } + f() != 1; // { dg-warning "not used" } + f() < 2; // { dg-warning "not used" } + f() > 3; // { dg-warning "not used" } + f() <= 4; // { dg-warning "not used" } + f() >= 5; // { dg-warning "not used" } + f() + 6; // { dg-warning "not used" } + f() - 7; // { dg-warning "not used" } + f() * 8; // { dg-warning "not used" } + f() / 9; // { dg-warning "not used" } + +f(); // { dg-warning "not used" } + -f(); // { dg-warning "not used" } + ++f(); + --f(); + f() = 10; + f() <<= 11; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-label-1.C b/gcc/testsuite/g++.dg/warn/Wunused-label-1.C new file mode 100644 index 000000000..96f49b321 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-label-1.C @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-Wunused-label" } + +extern void f9(); + +void +f1() +{ + l1: f9(); // { dg-warning "not used" } + l3: ; f9(); // { dg-warning "not used" } + l4: __attribute__ ((unused)) ; f9(); +} + +void +f2() +{ + label: __attribute ((unused)) ; +} + +void +f3() +{ + // The next line would be OK in C but is a syntax error in C++. + l2: __attribute__ ((unused)) f9(); // { dg-error "expected" } + // We still get an unused label warning--this is + // optional and can be removed if it ever changes. + // { dg-warning "not used" "expected" { target *-*-* } 24 } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-label-2.C b/gcc/testsuite/g++.dg/warn/Wunused-label-2.C new file mode 100644 index 000000000..a53fdedf3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-label-2.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +// If __attribute__ ((unused)) follows a label and precedes a +// declaration, we should get a warning for the label, not the +// declaration. + +void +f1() +{ + int i1; // { dg-warning "unused variable" } + l1: __attribute__ ((unused)) int i2; // { dg-warning "label \[^\n\]* not used" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-label-3.C b/gcc/testsuite/g++.dg/warn/Wunused-label-3.C new file mode 100644 index 000000000..7479ca20c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-label-3.C @@ -0,0 +1,51 @@ +// { dg-do compile } +// { dg-options "-Wunused-label" } + +extern void f9(); + +template +void +f1() +{ + if (i) + return; + + l1: f9(); // { dg-warning "not used" } + l3: ; f9(); // { dg-warning "not used" } + l4: __attribute__ ((unused)) ; f9(); +} + +template +void f1<0>(); + +template +void +f2() +{ + if (i) + return; + + l1: f9(); // { dg-warning "not used" } + l3: ; f9(); // { dg-warning "not used" } + l4: __attribute__ ((unused)) ; f9(); +} + +template +void f2<1>(); + +template +void +f3() +{ + void* lab; + l1: f9(); + l2: __attribute__ ((unused)) ; f9(); + lab = i ? &&l1 : &&l2; + goto *lab; +} + +template +void f3<0>(); + +template +void f3<1>(); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C new file mode 100644 index 000000000..08bfaa66b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-1.C @@ -0,0 +1,58 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } + +long +f1 (unsigned long long x) +{ + unsigned long long a = 1; + const union { unsigned long long l; unsigned int p[2]; } b = { x }; + const union { unsigned long long l; unsigned int p[2]; } c = { a }; + return b.p[0] + c.p[0]; +} + +int +f2 (int x, int y) +{ + int a = 1; + int b[] = { 1, 2, x, a, 3, 4 }; + return b[y]; +} + +int +f3 (int a) // { dg-warning "unused parameter" } +{ + return 0; +} + +int +f4 (int a) // { dg-warning "set but not used" } +{ + a = 1; + return 0; +} + +int +f5 (int a) +{ + a = 1; + return a; +} + +int +f6 (int &a) +{ + return a; +} + +void +f7 (int &a) +{ + a = 1; +} + +struct S +{ + S (int i) : j(i) {} + S (long i) : j(i + 1) {} + int j; +}; diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C new file mode 100644 index 000000000..d4276c0a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-2.C @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } + +template +long +f1 (unsigned long long x) +{ + unsigned long long a = 1; + const union { unsigned long long l; unsigned int p[2]; } b = { x }; + const union { unsigned long long l; unsigned int p[2]; } c = { a }; + return b.p[0] + c.p[0]; +} + +template +int +f2 (int x, int y) +{ + int a = 1; + int b[] = { 1, 2, x, a, 3, 4 }; + return b[y]; +} + +template +int +f3 (int a) // { dg-warning "unused parameter" } +{ + return 0; +} + +template +int +f4 (int a) // { dg-warning "set but not used" } +{ + a = 1; + return 0; +} + +template +int +f5 (int a) +{ + a = 1; + return a; +} + +void +test () +{ + (void) f1<0> (0); + (void) f2<0> (0, 0); + (void) f3<0> (0); + (void) f4<0> (0); + (void) f5<0> (0); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C new file mode 100644 index 000000000..3f0a0e7d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-3.C @@ -0,0 +1,71 @@ +// { dg-do compile } +// { dg-options "-Wunused -W" } +// Suppress a warning that is irrelevant to the purpose of this test. +// { dg-options "-Wunused -W -Wno-abi" { target arm_eabi } } + +#include + +struct A +{ + long a; + A () : a (0) { } + A (long x) : a (x) { } + operator long () const { return a; } + long operator- (const A& x) const { return a - x.a; } +}; + +long +fn1 (A a) +{ + return a - A (0); +} + +struct B +{ + bool operator() (const int x, const int y) const throw() { return x < y; } +}; + +template +bool +fn2 (int x, int y, T z) +{ + return z (x, y); +} + +bool +fn3 (void) +{ + return fn2 (1, 2, B ()); +} + +int +fn4 (va_list ap) +{ + return va_arg (ap, int); +} + +template +T +fn5 (va_list ap) +{ + return va_arg (ap, T); +} + +int +fn6 (va_list ap) +{ + return fn5 (ap); +} + +template +int +fn7 (T ap) +{ + return va_arg (ap, int); +} + +int +fn8 (va_list ap) +{ + return fn7 (ap); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-parm-4.C b/gcc/testsuite/g++.dg/warn/Wunused-parm-4.C new file mode 100644 index 000000000..fbad380f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-parm-4.C @@ -0,0 +1,24 @@ +// PR c++/47783 +// { dg-do compile } +// { dg-options "-Wunused -W" } + +struct R +{ + int &i; +}; + +void +foo (R r, int &s) +{ + r.i = 7; + s = 8; +} + +int +bar () +{ + int x = 1, y = 1; + R r = { x }; + foo (r, y); + return x + y; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-1.C b/gcc/testsuite/g++.dg/warn/Wunused-var-1.C new file mode 100644 index 000000000..89c110b0e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-1.C @@ -0,0 +1,8 @@ +// { dg-options "-Wunused" } +template struct X { static const int s = 2; }; +template int f() { const int v = 2; return X::s; } +template int g() { const int v = 2; return X::s; } +template int h() { const int v = 2; return X<1 ? v : 0>::s; } +template int f(); +template int g(); +template int h(); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-10.C b/gcc/testsuite/g++.dg/warn/Wunused-var-10.C new file mode 100644 index 000000000..ffdb89327 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-10.C @@ -0,0 +1,42 @@ +// PR c++/44412 +// { dg-do compile } +// { dg-options "-Wunused" } + +struct S +{ + static const int a = 3; + static int b; + int c; +}; + +const int S::a; +int S::b = 4; + +int +f1 () +{ + S s; + return s.a; +} + +int +f2 () +{ + S s; + return s.b; +} + +void +f3 () +{ + S s; // { dg-warning "set but not used" } + s.c = 6; +} + +int +f4 () +{ + S s; + s.c = 6; + return s.c; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-11.C b/gcc/testsuite/g++.dg/warn/Wunused-var-11.C new file mode 100644 index 000000000..c7c1bf35f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-11.C @@ -0,0 +1,33 @@ +// PR c++/44412 +// { dg-do compile } +// { dg-options "-Wunused" } + +struct S +{ + int foo (); + static int bar (); +}; + +int S::foo () +{ + return 5; +} + +int S::bar () +{ + return 6; +} + +int +f1 () +{ + S s; + return s.foo (); +} + +int +f2 () +{ + S s; + return s.bar (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-12.C b/gcc/testsuite/g++.dg/warn/Wunused-var-12.C new file mode 100644 index 000000000..3300cbe3d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-12.C @@ -0,0 +1,36 @@ +// PR c++/44444 +// { dg-do compile } +// { dg-options "-Wunused" } + +struct S +{ + const int &u; + const int &v; + S (const int &a, const int &b) : u(a), v(b) { } +}; + +bool +f1 () +{ + bool t = false; + S z = S (1, 2); + t |= z.u == 1; + t |= z.v == 2; + return t; +} + +void +f2 () +{ + S z = S (1, 2); + z.u; // { dg-warning "no effect" } +} + +int i; + +void +f3 () +{ + S z = S (1, 2); + i++, z.u; // { dg-warning "no effect" } +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-13.C b/gcc/testsuite/g++.dg/warn/Wunused-var-13.C new file mode 100644 index 000000000..43df81d88 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-13.C @@ -0,0 +1,22 @@ +// PR c++/44619 +// { dg-do compile } +// { dg-options "-Wunused -W" } + +struct S { int x, y; }; + +int +f1 () +{ + struct S p; + int S::*q = &S::x; + p.*q = 5; + return p.*q; +} + +int +f2 (struct S *p, int S::*q) +{ + struct S *r = p; + int S::*s = q; + return r->*s; +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-14.C b/gcc/testsuite/g++.dg/warn/Wunused-var-14.C new file mode 100644 index 000000000..a552b56da --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-14.C @@ -0,0 +1,17 @@ +// PR c++/44682 +// { dg-do compile } +// { dg-options "-Wunused" } + +struct S { virtual ~S () {} }; +struct T { virtual ~T () {} }; +struct U : S, T {}; + +void f (U &); + +void +g (void *v) +{ + T *t = static_cast (v); + U *u = static_cast (t); + f (*u); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-15.C b/gcc/testsuite/g++.dg/warn/Wunused-var-15.C new file mode 100644 index 000000000..9782ccbd9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-15.C @@ -0,0 +1,29 @@ +// PR c++/45588 +// { dg-do compile } +// { dg-options "-Wunused" } + +void bar (unsigned char *); + +template +struct S +{ + static const int k = 6; +}; + +template +const int S::k; + +template +void +foo () +{ + const int i = S::k; + unsigned char a[i]; + bar (a); +} + +void +baz () +{ + foo<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-2.C b/gcc/testsuite/g++.dg/warn/Wunused-var-2.C new file mode 100644 index 000000000..0b21ef116 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-2.C @@ -0,0 +1,104 @@ +// { dg-options "-Wunused -W" } + +extern void foo (); + +void +f1 () +{ + try + { + foo (); + } + catch (int i) + { + } + catch (double d) + { + } +} + +void +f2 (int x) +{ + int a = 0; + x++; + ++a; +} + +struct A +{ + bool foo () const { return true; } +}; + +int +f3 () +{ + A a; + bool b = a.foo (); + return b; +} + +struct B +{ + int i; + B (int j); +}; + +void +f4 () +{ + B b (6); +} + +struct C +{ + int i; + C (int j) : i (j) {} +}; + +void +f5 () +{ + C c (6); +} + +struct D +{ + int i; + D (int j) : i (j) {} + ~D (); +}; + +void +f6 () +{ + D d (6); +} + +int *f7 (int s) +{ + return new int[s]; +} + +template +T *f8 (int s) +{ + return new T[s]; +} + +template int *f8 (int); + +void +f9 (char *p) +{ + delete p; +} + +template +void +f10 (T *p) +{ + delete p; +} + +template void f10 (char *); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-3.C b/gcc/testsuite/g++.dg/warn/Wunused-var-3.C new file mode 100644 index 000000000..cd8931d71 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-3.C @@ -0,0 +1,110 @@ +// { dg-options "-Wunused -W" } + +#include +#include + +void +f1 (int a, ...) +{ + va_list ap; + va_start (ap, a); + va_end (ap); +} + +int +f2 (int a, ...) +{ + va_list ap; + va_start (ap, a); + int i = va_arg (ap, int); + va_end (ap); + return i; +} + +struct A { int a; A (); virtual ~A (); }; +struct B : virtual A { int b; }; + +struct B * +f3 (struct A *a) +{ + return dynamic_cast (a); +} + +struct A * +f4 (struct B *a) +{ + return static_cast (a); +} + +struct A * +f5 (struct B *a) +{ + return reinterpret_cast (a); +} + +struct A * +f6 (const struct A *a) +{ + return const_cast (a); +} + +int +f7 (long a) +{ + return (int) a; +} + +int +f8 (long a) +{ + return int (a); +} + +struct C +{ + operator unsigned int() { return 42; } +}; + +unsigned int +f9 () +{ + C u; + return u; +} + +struct D +{ + operator int & (); + operator const int & () const; +}; + +void foo (int &); +void foo (const int &); + +void +f10 () +{ + const D x = D (); + foo (x); +} + +int +f11 (int a) +{ + return typeid (a) == typeid (int); +} + +struct E +{ + int e () {return 0;} +}; + +template +int +f12 (E a) +{ + __decltype (a.e()) i; + return i; +} + +template <> int f12 (E); diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-4.C b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C new file mode 100644 index 000000000..11ed7afea --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-4.C @@ -0,0 +1,50 @@ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +struct S { int e; }; + +int +f1 (void) +{ + int a; + int b; + int c; + int d; + S s; + a = 1; + b = 2; + c = 3; + d = 4; + s.e = 5; + __typeof (c) e; // { dg-warning "set but not used" } + __decltype (d) f; // { dg-warning "set but not used" } + __decltype (s.e) g; // { dg-warning "set but not used" } + e = 1; + f = 1; + g = 1; + return sizeof (a) + __alignof__ (b); +} + +template +int f2 (void) +{ + int a; + int b; + int c; + int d; + a = 1; + b = 2; + c = 3; + d = 4; + __typeof (c) e; // { dg-warning "set but not used" } + __decltype (d) f; // { dg-warning "set but not used" } + e = 1; + f = 1; + return sizeof (a) + __alignof__ (b); +} + +void +test (void) +{ + (void) f2<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-5.C b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C new file mode 100644 index 000000000..7fcaa955c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-5.C @@ -0,0 +1,227 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template +void +f1 (void) +{ + int a; // { dg-warning "set but not used" } + int b; + int c; + c = 1; + a = b = c; +} + +template +void +f2 (int x) +{ + int a; // { dg-warning "set but not used" } + int b; + int c; // { dg-warning "set but not used" } + c = (a = x, b = x); +} + +template +int +f3 (int x) +{ + int a; + return a = x; +} + +template +int +f4 (int x) +{ + int a; + a = x; + return a; +} + +template +void +f5 (int x) +{ + int a[2]; // { dg-warning "set but not used" } + int b; + int *c, d[2]; + c = d; + b = x; + a[b] = 1; + c[b] = 1; +} + +template +int +f6 (int x) +{ + int a[2]; + int b; + b = x; + a[b] = 1; + return a[b]; +} + +template +void +f7 (int x, int *p) +{ + int *a[2]; + a[x] = p; + a[x][x] = x; +} + +struct S { int i; }; + +template +void +f8 (void) +{ + struct S s; // { dg-warning "set but not used" } + s.i = 6; +} + +template +int +f9 (void) +{ + struct S s; + s.i = 6; + return s.i; +} + +template +struct S +f10 (void) +{ + struct S s; + s.i = 6; + return s; +} + +extern int foo11 (int *); + +template +void +f11 (void) +{ + int a[2]; + foo11 (a); +} + +template +void +f12 (void) +{ + int a; + a = 1; + a; // { dg-warning "statement has no effect" } +} + +template +void +f13 (void (*x) (void)) +{ + void (*a) (void); + a = x; + a (); +} + +template +void +f14 (void (*x) (void)) +{ + void (*a) (void); // { dg-warning "set but not used" } + a = x; +} + +extern void foo15 (int *); + +template +void +f15 (void) +{ + int a[10]; + int *b = a + 2; + foo15 (b); +} + +extern void foo16 (int **); + +template +void +f16 (void) +{ + int a[10]; + int *b[] = { a, a + 2 }; + foo16 (b); +} + +template +void +f17 (int x) +{ + long a; // { dg-warning "set but not used" } + int b; + a = b = x; +} + +template +void +f18 (int x) +{ + int a; // { dg-warning "set but not used" } + int b; + a = (char) (b = x); +} + +template +int +f19 (int x, int y, int z) +{ + int a; + int b; + a = x; + b = y; + return z ? a : b; +} + +template +int * +f20 (int x) +{ + static int a[] = { 3, 4, 5, 6 }; + static int b[] = { 4, 5, 6, 7 }; + static int c[] = { 5, 6, 7, 8 }; // { dg-warning "set but not used" } + c[1] = 1; + return x ? a : b; +} + +S s; + +void +test () +{ + int i = 0; + f1<0> (); + f2<0> (0); + (void) f3<0> (0); + (void) f4<0> (0); + f5<0> (0); + (void) f6<0> (0); + f7<0> (0, &i); + f8<0> (); + (void) f9<0> (); + s = f10<0> (); + f11<0> (); + f12<0> (); + f13<0> (f1<0>); + f14<0> (f1<0>); + f15<0> (); + f16<0> (); + f17<0> (0); + f18<0> (0); + (void) f19<0> (0, 0, 0); + (void) f20<0> (0); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-6.C b/gcc/testsuite/g++.dg/warn/Wunused-var-6.C new file mode 100644 index 000000000..0fb8e5cac --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-6.C @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template +int +f1 (void) +{ + int c = ({ + int a; + a = 1; + a; }); + return c; +} + +template +void +f2 (void) +{ + int f; + f = 0; + __asm__ __volatile__ ("" : "+r" (f)); +} + +void +test () +{ + (void) f1<0> (); + f2<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-7.C b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C new file mode 100644 index 000000000..cf1b605c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-7.C @@ -0,0 +1,48 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template +void +f1 (void) +{ + _Complex int a; // { dg-warning "set but not used" } + _Complex double b; // { dg-warning "set but not used" } + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; +} + +template +int +f2 (void) +{ + _Complex int a; + _Complex double b; + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; + return __real__ a + __imag__ b; +} + +template +_Complex double +f3 (void) +{ + _Complex int a; + _Complex double b; + __real__ a = 1; + __imag__ a = 2; + __real__ b = 3.0; + __imag__ b = 4.0; + return a + b; +} + +void +test () +{ + f1<0> (); + (void) f2<0> (); + (void) f3<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-8.C b/gcc/testsuite/g++.dg/warn/Wunused-var-8.C new file mode 100644 index 000000000..69fc6fb79 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-8.C @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-Wunused" } + +template +void +f1 (void) +{ + extern int extvari; + extvari = 1; +} + +int extvarj; + +template +void +f2 (void) +{ + extern int extvarj; + extvarj = 1; +} + +static int extvark; + +template +void +f3 (void) +{ + extern int extvark; + extvark = 1; +} + +template +int +f4 (void) +{ + return extvark; +} + +void +test () +{ + f1<0> (); + f2<0> (); + f3<0> (); + (void) f4<0> (); +} diff --git a/gcc/testsuite/g++.dg/warn/Wunused-var-9.C b/gcc/testsuite/g++.dg/warn/Wunused-var-9.C new file mode 100644 index 000000000..cb422f45c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wunused-var-9.C @@ -0,0 +1,13 @@ +/* PR c++/44062 */ +/* { dg-do compile } */ +/* { dg-options "-Wunused" } */ + +void +f () +{ + int i = 4; + static_cast (i); + int j; + j = 5; + static_cast (j); +} diff --git a/gcc/testsuite/g++.dg/warn/Wvla-1.C b/gcc/testsuite/g++.dg/warn/Wvla-1.C new file mode 100644 index 000000000..ca3669aec --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wvla-1.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-Wvla" } */ + +void func (int i) +{ + int array[i]; /* { dg-warning "variable length array 'array' is used" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wvla-2.C b/gcc/testsuite/g++.dg/warn/Wvla-2.C new file mode 100644 index 000000000..ba83ac1a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wvla-2.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -Wvla" } */ + +void func (int i) +{ + int array[i]; /* { dg-error "ISO C.* forbids variable.* array 'array'" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/Wvla-3.C b/gcc/testsuite/g++.dg/warn/Wvla-3.C new file mode 100644 index 000000000..259c576b2 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wvla-3.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors -Wno-vla" } */ + +void func (int i) +{ + int array[i]; +} diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C new file mode 100644 index 000000000..cf193e0cb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.C @@ -0,0 +1,18 @@ +// Test for the warning of exposing types from an anonymous namespace +// { dg-do compile } + +#include "anonymous-namespace-1.h" + +namespace { + class good { }; +} + +class foo::bar : public good { }; +class foobar1 +{ + good g; +}; + +#line 17 "foo.C" +class foobar : public bad { }; // { dg-warning "uses the anonymous namespace" } +class foobar2 { bad b; }; // { dg-warning "uses the anonymous namespace" } diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.h b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.h new file mode 100644 index 000000000..0d3e239e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-1.h @@ -0,0 +1,7 @@ +class foo { + class bar; +}; + +namespace { + class bad { }; +} diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C new file mode 100644 index 000000000..4048f3959 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.C @@ -0,0 +1,29 @@ +// Test for the warning of exposing types from an anonymous namespace +// { dg-do compile } +// +#include "anonymous-namespace-2.h" + +namespace { + struct good { }; +} + +struct g1 { + good * A; +}; +struct g2 { + good * A[1]; +}; +struct g3 { + good (*A)[1]; +}; + +#line 21 "foo.C" +struct b1 { // { dg-warning "uses the anonymous namespace" } + bad * B; +}; +struct b2 { // { dg-warning "uses the anonymous namespace" } + bad * B[1]; +}; +struct b3 { // { dg-warning "uses the anonymous namespace" } + bad (*B)[1]; +}; diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.h b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.h new file mode 100644 index 000000000..ce5d05c2a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-2.h @@ -0,0 +1,3 @@ +namespace { + struct bad { }; +} diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C new file mode 100644 index 000000000..0ba6790f4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.C @@ -0,0 +1,13 @@ +// Test for the warning of exposing types from an anonymous namespace +// { dg-do compile } +// +#include +#include "anonymous-namespace-3.h" + +struct B { std::auto_ptr p; }; + +#line 10 "foo.C" +struct C // { dg-warning "uses the anonymous namespace" } +{ + std::auto_ptr p; +}; diff --git a/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.h b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.h new file mode 100644 index 000000000..0c7c1f8e4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/anonymous-namespace-3.h @@ -0,0 +1 @@ +namespace { struct A; } diff --git a/gcc/testsuite/g++.dg/warn/changes-meaning.C b/gcc/testsuite/g++.dg/warn/changes-meaning.C new file mode 100644 index 000000000..fdbddf820 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/changes-meaning.C @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-fpermissive" } */ + +template class auto_ptr {}; /* { dg-warning "changes meaning" } */ +template +class counted_ptr +{ +public: + auto_ptr<_Tp> auto_ptr(); /* { dg-warning "" } */ +}; + diff --git a/gcc/testsuite/g++.dg/warn/compare1.C b/gcc/testsuite/g++.dg/warn/compare1.C new file mode 100644 index 000000000..e00592262 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/compare1.C @@ -0,0 +1,10 @@ +/* -Wall is supposed to trigger -Wsign-compare for C++. PR 10604. + See also gcc.dg/compare7.c. */ + +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +int f(unsigned a, int b) +{ + return a < b; /* { dg-warning "signed and unsigned" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/conv1.C b/gcc/testsuite/g++.dg/warn/conv1.C new file mode 100644 index 000000000..d06cbd586 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/conv1.C @@ -0,0 +1,33 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 20 Apr 2003 + +// PR 10337, unneeded warning + +class A { + public: + A() {} +}; + +class B : public A { + public: + B() {} + void operator=(const A& b) {} + void operator=(const B& b) {} +}; + +class C { + public: + C() {} + operator B &() { return _b; } + operator const B &() const { return _b; } + + B _b; +}; + +int main() { + B b; + C c; + b = c; +} diff --git a/gcc/testsuite/g++.dg/warn/conv2.C b/gcc/testsuite/g++.dg/warn/conv2.C new file mode 100644 index 000000000..45f518346 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/conv2.C @@ -0,0 +1,5 @@ +// PR c++/13932 +// { dg-options "-Wconversion" } + +int i = 1.; +int j = 1.1; // { dg-warning "conversion" } diff --git a/gcc/testsuite/g++.dg/warn/conv3.C b/gcc/testsuite/g++.dg/warn/conv3.C new file mode 100644 index 000000000..5900c3aac --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/conv3.C @@ -0,0 +1,4 @@ +// PR c++/19457 + +int i=-1; +unsigned int j= ~0; // { dg-bogus "" } diff --git a/gcc/testsuite/g++.dg/warn/conv4.C b/gcc/testsuite/g++.dg/warn/conv4.C new file mode 100644 index 000000000..a15ef8bf1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/conv4.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// This file should compile cleanly by default and not warn on the conversions. +int func1(int i) +{ + return i; +} + +int main() +{ + float f; + long l; + unsigned long ul; + + f = 1.5f; + + l = f; + ul = -1; + func1(f); + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/conversion-function-1.C b/gcc/testsuite/g++.dg/warn/conversion-function-1.C new file mode 100644 index 000000000..878011cf3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/conversion-function-1.C @@ -0,0 +1,8 @@ +// Copyright (C) 2003 Free Software Foundation +// Contributed by Gabriel Dos Reis +// { dg-options "-Wno-conversion" } + +struct A { + operator A&(); +}; + diff --git a/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-1.C b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-1.C new file mode 100644 index 000000000..3e84c0921 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-1.C @@ -0,0 +1,9 @@ +// { dg-options "-Wctor-dtor-privacy" } + +struct C { // { dg-warning "" } + static bool result; +private: + static bool check(); +}; + +bool C::result = check(); diff --git a/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-2.C b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-2.C new file mode 100644 index 000000000..16873ab78 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/ctor-dtor-privacy-2.C @@ -0,0 +1,7 @@ +struct C { + static bool result; +private: + static bool check(); +}; + +bool C::result = check(); diff --git a/gcc/testsuite/g++.dg/warn/ctor-init-1.C b/gcc/testsuite/g++.dg/warn/ctor-init-1.C new file mode 100644 index 000000000..0796972fc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/ctor-init-1.C @@ -0,0 +1,9 @@ +// PR c++/11554 +// { dg-options "-Wall" } + +struct Y { + Y (); + int i1, i2; // { dg-warning "" } +}; + +Y::Y () : i2(0), i1(0) {} // { dg-warning "" } diff --git a/gcc/testsuite/g++.dg/warn/ctor1.C b/gcc/testsuite/g++.dg/warn/ctor1.C new file mode 100644 index 000000000..00a6c952b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/ctor1.C @@ -0,0 +1,13 @@ +// PR c++/35734 +// { dg-options "-W" } + +struct A +{ + A(); + template A(const T&); +}; + +struct B : A +{ + B(const B&) {} // { dg-warning "base class" } +}; diff --git a/gcc/testsuite/g++.dg/warn/deprecated-2.C b/gcc/testsuite/g++.dg/warn/deprecated-2.C new file mode 100644 index 000000000..d79a7f9e6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-2.C @@ -0,0 +1,11 @@ +/* Test __attribute__((deprecated)). Test merging with multiple + declarations. Bug 7425 (C++ version). */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void func(void); +void func(void) __attribute__((deprecated)); + +void f(void) { + func(); /* { dg-warning "'void func\\(\\)' is deprecated" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated-3.C b/gcc/testsuite/g++.dg/warn/deprecated-3.C new file mode 100644 index 000000000..8b4378c41 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-3.C @@ -0,0 +1,14 @@ +/* PR 17947 bad warning with implicit conversion and __attribute__((deprecated)) */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct Foo +{ + operator int() __attribute__((deprecated)); +}; + +void g(void) +{ + Foo f; + (int)f; // { dg-warning "'Foo::operator int\\(\\)' is deprecated \\(declared at" } +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated-4.C b/gcc/testsuite/g++.dg/warn/deprecated-4.C new file mode 100644 index 000000000..e2f1a2c33 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-4.C @@ -0,0 +1,9 @@ +// PR c++/15269 + +struct B { + virtual int foo() __attribute__((deprecated)); +}; + +int main(void) { + ((B*)0)->foo(); // { dg-warning "deprecated" } +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated-5.C b/gcc/testsuite/g++.dg/warn/deprecated-5.C new file mode 100644 index 000000000..a015bd50b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-5.C @@ -0,0 +1,4 @@ +// PR c++/16370 + +struct Foo { int i; } __attribute__ ((deprecated)); +void foo() { Foo f; } // { dg-warning "deprecated" } diff --git a/gcc/testsuite/g++.dg/warn/deprecated-6.C b/gcc/testsuite/g++.dg/warn/deprecated-6.C new file mode 100644 index 000000000..8ce6ac02d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated-6.C @@ -0,0 +1,110 @@ +/* Test __attribute__ ((deprecated("message"))) */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations -fmessage-length=0" } */ + +typedef int INT1 __attribute__((deprecated("Please avoid INT1"))); +typedef INT1 INT2 __attribute__ ((__deprecated__("Please avoid INT2"))); + +typedef INT1 INT1a; /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ + +INT1 should_be_unavailable; /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ +INT1a should_not_be_deprecated; + +INT1 f1(void) __attribute__ ((deprecated("Please avoid f1"))); +INT1 f2(void) { return 0; } /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ + +INT2 f3(void) __attribute__ ((__deprecated__("Please avoid f3"))); +INT2 f4(void) { return 0; } /* { dg-warning "'INT2' is deprecated .declared at \[^\n\]*: Please avoid INT2" "" } */ +int f5(INT2 x); /* { dg-warning "'INT2' is deprecated" "" } */ +int f6(INT2 x) __attribute__ ((__deprecated__("Please avoid f6"))); + +typedef enum Color {red, green, blue} Color __attribute__((deprecated("Please avoid Color"))); + +int g1; +int g2 __attribute__ ((deprecated("Please avoid g2"))); +int g3 __attribute__ ((__deprecated__("Please avoid g3"))); +Color k; /* { dg-warning "'Color' is deprecated .declared at \[^\n\]*: Please avoid Color" "" } */ + +typedef struct { + int field1; + int field2 __attribute__ ((deprecated("Please avoid field2"))); + int field3; + int field4 __attribute__ ((__deprecated__("Please avoid field4"))); + union { + int field5; + int field6 __attribute__ ((deprecated("Please avoid field6"))); + } u1; + int field7:1; + int field8:1 __attribute__ ((deprecated("Please avoid field8"))); + union { + int field9; + int field10; + } u2 __attribute__ ((deprecated("Please avoid u2"))); +} S1; + +int func1() +{ + INT1 w; /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ + int x __attribute__ ((deprecated("Please avoid x"))); + int y __attribute__ ((__deprecated__("Please avoid y"))); + int z; + int (*pf)() = f1; /* { dg-warning "'INT1 f1\\(\\)' is deprecated .declared at \[^\n\]*: Please avoid f1" "" } */ + + z = w + x + y + g1 + g2 + g3; /* { dg-warning "'x' is deprecated .declared at \[^\n\]*: Please avoid x" "" } */ + /* { dg-warning "'y' is deprecated .declared at \[^\n\]*: Please avoid y" "y" { target *-*-* } 53 } */ + /* { dg-warning "'g2' is deprecated .declared at \[^\n\]*: Please avoid g2" "g2" { target *-*-* } 53 } */ + /* { dg-warning "'g3' is deprecated .declared at \[^\n\]*: Please avoid g3" "g3" { target *-*-* } 53 } */ + return f1(); /* { dg-warning "'INT1 f1\\(\\)' is deprecated .declared at \[^\n\]*: Please avoid f1" "f1" } */ +} + +int func2(S1 *p) +{ + S1 lp; + + if (p->field1) + return p->field2; /* { dg-warning "'S1::field2' is deprecated .declared at \[^\n\]*: Please avoid field2" "" } */ + else if (lp.field4) /* { dg-warning "'S1::field4' is deprecated .declared at \[^\n\]*: Please avoid field4" "" } */ + return p->field3; + + p->u1.field5 = g1 + p->field7; + p->u2.field9; /* { dg-warning "'S1::u2' is deprecated .declared at \[^\n\]*: Please avoid u2" "" } */ + return p->u1.field6 + p->field8; /* { dg-warning "'S1::::field6' is deprecated .declared at \[^\n\]*: Please avoid field6" "" } */ + /* { dg-warning "'S1::field8' is deprecated .declared at \[^\n\]*: Please avoid field8" "field8" { target *-*-* } 71 } */ +} + +struct SS1 { + int x; + INT1 y; /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ +} __attribute__ ((deprecated("Please avoid SS1"))); + +struct SS1 *p1; /* { dg-warning "'SS1' is deprecated .declared at \[^\n\]*: Please avoid SS1" "" } */ + +struct __attribute__ ((__deprecated__("Please avoid SS2"))) SS2 { + int x; + INT1 y; /* { dg-warning "'INT1' is deprecated .declared at \[^\n\]*: Please avoid INT1" "" } */ +}; + +struct SS2 *p2; /* { dg-warning "'SS2' is deprecated .declared at \[^\n\]*: Please avoid SS2" "" } */ + +class T { + public: + void member1(int) __attribute__ ((deprecated("Please avoid member1"))); + void member2(INT1) __attribute__ ((__deprecated__("Please avoid member2"))); /* { dg-warning "'INT1' is deprecated" "" } */ + int member3(T *); + int x; +} __attribute__ ((deprecated("Please avoid T"))); + +T *p3; // { dg-warning "'T' is deprecated .declared at \[^\n\]*: Please avoid T" } + +inline void T::member1(int) {} + +int T::member3(T *p) // { dg-warning "'T' is deprecated .declared at \[^\n\]*: Please avoid T" } +{ + p->member1(1); /* { dg-warning "'void T::member1\\(int\\)' is deprecated .declared at \[^\n\]*: Please avoid member1" "" } */ + (*p).member1(2); /* { dg-warning "'void T::member1\\(int\\)' is deprecated .declared at \[^\n\]*: Please avoid member1" "" } */ + p->member2(1); /* { dg-warning "'void T::member2\\(INT1\\)' is deprecated .declared at \[^\n\]*: Please avoid member2" "" } */ + (*p).member2(2); /* { dg-warning "'void T::member2\\(INT1\\)' is deprecated .declared at \[^\n\]*: Please avoid member2" "" } */ + p->member3(p); + (*p).member3(p); + return f1(); /* { dg-warning "'INT1 f1\\(\\)' is deprecated .declared at \[^\n\]*: Please avoid f1" "" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/deprecated.C b/gcc/testsuite/g++.dg/warn/deprecated.C new file mode 100644 index 000000000..210740814 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/deprecated.C @@ -0,0 +1,117 @@ +/* Test __attribute__ ((deprecated)) */ +/* { dg-do compile } */ +/* { dg-options "-Wdeprecated-declarations -fmessage-length=0" } */ + +#if 1 +typedef int INT1 __attribute__((deprecated)); +typedef INT1 INT2 __attribute__ ((__deprecated__)); + +typedef INT1 INT1a; /* { dg-warning "'INT1' is deprecated" "" } */ +typedef INT1 INT1b __attribute__ ((deprecated)); + +INT1 should_be_unavailable; /* { dg-warning "'INT1' is deprecated" "" } */ +INT1a should_not_be_deprecated; + +INT1 f1(void) __attribute__ ((deprecated)); +INT1 f2(void) { return 0; } /* { dg-warning "'INT1' is deprecated" "" } */ + +INT2 f3(void) __attribute__ ((__deprecated__)); +INT2 f4(void) { return 0; } /* { dg-warning "'INT2' is deprecated" "" } */ +int f5(INT2 x); /* { dg-warning "'INT2' is deprecated" "" } */ +int f6(INT2 x) __attribute__ ((__deprecated__)); + +typedef enum Color {red, green, blue} Color __attribute__((deprecated)); + +int g1; +int g2 __attribute__ ((deprecated)); +int g3 __attribute__ ((__deprecated__)); +Color k; /* { dg-warning "'Color' is deprecated" "" } */ + +typedef struct { + int field1; + int field2 __attribute__ ((deprecated)); + int field3; + int field4 __attribute__ ((__deprecated__)); + union { + int field5; + int field6 __attribute__ ((deprecated)); + } u1; + int field7:1; + int field8:1 __attribute__ ((deprecated)); + union { + int field9; + int field10; + } u2 __attribute__ ((deprecated)); +} S1; + +int func1() +{ + INT1 w; /* { dg-warning "'INT1' is deprecated" "" } */ + int x __attribute__ ((deprecated)); + int y __attribute__ ((__deprecated__)); + int z; + int (*pf)() = f1; /* { dg-warning "'INT1 f1\\(\\)' is deprecated" "" } */ + + z = w + x + y + g1 + g2 + g3; /* { dg-warning "'x' is deprecated" "" } */ + /* { dg-warning "'y' is deprecated" "y" { target *-*-* } 55 } */ + /* { dg-warning "'g2' is deprecated" "g2" { target *-*-* } 55 } */ + /* { dg-warning "'g3' is deprecated" "g3" { target *-*-* } 55 } */ + return f1(); /* { dg-warning "'INT1 f1\\(\\)' is deprecated" "f1" } */ +} + +int func2(S1 *p) +{ + S1 lp; + + if (p->field1) + return p->field2; /* { dg-warning "'S1::field2' is deprecated" "" } */ + else if (lp.field4) /* { dg-warning "'S1::field4' is deprecated" "" } */ + return p->field3; + + p->u1.field5 = g1 + p->field7; + p->u2.field9; /* { dg-warning "'S1::u2' is deprecated" "" } */ + return p->u1.field6 + p->field8; /* { dg-warning "'S1::::field6' is deprecated" "" } */ + /* { dg-warning "'S1::field8' is deprecated" "field8" { target *-*-* } 73 } */ +} + +struct SS1 { + int x; + INT1 y; /* { dg-warning "'INT1' is deprecated" "" } */ +} __attribute__ ((deprecated)); + +struct SS1 *p1; /* { dg-warning "'SS1' is deprecated" "" } */ + +struct __attribute__ ((__deprecated__)) SS2 { + int x; + INT1 y; /* { dg-warning "'INT1' is deprecated" "" } */ +}; + +struct SS2 *p2; /* { dg-warning "'SS2' is deprecated" "" } */ +#endif + +#ifdef __cplusplus +class T { + public: + void member1(int) __attribute__ ((deprecated)); + void member2(INT1) __attribute__ ((__deprecated__)); /* { dg-warning "'INT1' is deprecated" "" } */ + int member3(T *); + int x; +} __attribute__ ((deprecated)); + +T *p3; // { dg-warning "'T' is deprecated" } + +inline void T::member1(int) {} + +int T::member3(T *p) // { dg-warning "'T' is deprecated" } +{ + p->member1(1); /* { dg-warning "'void T::member1\\(int\\)' is deprecated" "" } */ + (*p).member1(2); /* { dg-warning "'void T::member1\\(int\\)' is deprecated" "" } */ + p->member2(1); /* { dg-warning "'void T::member2\\(INT1\\)' is deprecated" "" } */ + (*p).member2(2); /* { dg-warning "'void T::member2\\(INT1\\)' is deprecated" "" } */ + p->member3(p); + (*p).member3(p); + return f1(); /* { dg-warning "'INT1 f1\\(\\)' is deprecated" "" } */ +} +#endif + + diff --git a/gcc/testsuite/g++.dg/warn/do-empty.C b/gcc/testsuite/g++.dg/warn/do-empty.C new file mode 100644 index 000000000..350261d48 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/do-empty.C @@ -0,0 +1,15 @@ +/* Test diagnostics for empty bodies in do / while. */ +/* { dg-do compile } */ +/* { dg-options "-Wempty-body" } */ + +void +f (int x) +{ + do + ; /* { dg-warning "empty body in" } */ + while (x--); + + do + {} /* { dg-bogus "empty body in" } */ + while (++x < 10); +} diff --git a/gcc/testsuite/g++.dg/warn/effc1.C b/gcc/testsuite/g++.dg/warn/effc1.C new file mode 100644 index 000000000..345f8d1b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/effc1.C @@ -0,0 +1,16 @@ +// { dg-options -Weffc++ } +// { dg-do compile } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Apr 2002 + +// Bug 5719 + +class A +{ + public: + A & operator+=( int ); + A & operator+( int ); // { dg-warning ".* should return by value" "" } + A operator+=( float ); + A operator+( float ); +}; diff --git a/gcc/testsuite/g++.dg/warn/effc2.C b/gcc/testsuite/g++.dg/warn/effc2.C new file mode 100644 index 000000000..fb765f0d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/effc2.C @@ -0,0 +1,39 @@ +// { dg-do compile } +// { dg-options "-Weffc++" } +// Contributed by Benjamin Kosnik +// PR c++/16169 : Improve -Weffc++ rule 15 + +struct A { + const A& foo(); + const A& operator=(int) + { return foo(); } +}; + +struct B { + B& foo(); + B& operator=(int) + { return foo(); } +}; + +struct C { + C& operator=(int) + { return *this; } +}; + +struct D { + D operator=(int) + { return *this; } // { dg-warning "should return a reference" } +}; + +struct E { + E& foo(); + E operator=(int) + { return foo(); } // { dg-warning "should return a reference" } +}; + +struct F +{ + operator float(); + float operator=(int) + { return *this; } // { dg-warning "should return a reference" } +}; diff --git a/gcc/testsuite/g++.dg/warn/effc3.C b/gcc/testsuite/g++.dg/warn/effc3.C new file mode 100644 index 000000000..ba2cc0399 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/effc3.C @@ -0,0 +1,58 @@ +// { dg-do compile } +// { dg-options "-Weffc++" } +// Contributed by Benjamin Kosnik +// PR c++/16165 and PR c++/8211: Improve item 11 of -Weffc++ + + +// We should not warn for this class since this kind of pointers can +// never hold dynamic memory. +struct A { + void (*func1)(void); + void (A::*func2)(void); + int A::*func3; + + int a; + void b(void); + + A(); + ~A(); +}; + +// We do not warn for this class because there is no destructor, so we +// assume there is no dynamic memory allocated (it could point to a +// global variable). +struct B { + int *ptr; + B(); +}; + + +// We should emit a warning for these +struct C1 { // { dg-warning "" "" } + int *ptr; + C1(); + ~C1(); +}; + +struct C2 { // { dg-warning "" "" } + int *ptr; + C2(); + C2(const C2&); + ~C2(); +}; + +struct C3 { // { dg-warning "" "" } + int *ptr; + C3(); + ~C3(); + C3& operator=(const C3&); +}; + +// But not for this +struct C4 { + int *ptr; + C4(); + C4(const C4&); + ~C4(); + C4& operator=(const C4&); +}; diff --git a/gcc/testsuite/g++.dg/warn/empty-body.C b/gcc/testsuite/g++.dg/warn/empty-body.C new file mode 100644 index 000000000..064a09dde --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/empty-body.C @@ -0,0 +1,12 @@ +// PR c++/5520 +// { dg-options "-O2 -Wempty-body" } + +void breakme() +{ + if(1) ; // { dg-warning "empty body" } + if(1) {} // { dg-bogus "empty body" } + if(1) (void)0; // { dg-bogus "empty body" } + if(1) {} else; // { dg-warning "empty body" } + if(1) {} else (void)0; // // { dg-bogus "empty body" } + if(1) ; else (void)0; // // { dg-bogus "empty body" } +} diff --git a/gcc/testsuite/g++.dg/warn/format1.C b/gcc/testsuite/g++.dg/warn/format1.C new file mode 100644 index 000000000..27bc414b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/format1.C @@ -0,0 +1,15 @@ +// Test that formats get checked according to C94. +// Origin: Joseph Myers . +// { dg-do compile } +// { dg-options "-ansi -pedantic -Wformat" } + +#include + +void +foo (int i, int *ip, __WINT_TYPE__ lc, wchar_t *ls) +{ + std::printf ("%d%ls%lc\n", i, ls, lc); + std::printf ("%d", ls); // { dg-warning "format" "printf warning" } + std::scanf ("%d%lc%ls%l[abc]", ip, ls, ls, ls); + std::scanf ("%hd", ip); // { dg-warning "format" "scanf warning" } +} diff --git a/gcc/testsuite/g++.dg/warn/format2.C b/gcc/testsuite/g++.dg/warn/format2.C new file mode 100644 index 000000000..639bc668b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/format2.C @@ -0,0 +1,32 @@ +// Test for format attributes: test applying them to types in C++. +// Origin: Joseph Myers +// { dg-do compile } +// { dg-options "-Wformat" } + +__attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...); +void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2))); +void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...); +void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...); + +char * (__attribute__((format_arg(1))) *tformat_arg) (const char *); + +void +baz (int i) +{ + (*tformatprintf0) ("%d", i); + (*tformatprintf0) ((*tformat_arg) ("%d"), i); + (*tformatprintf0) ("%"); // { dg-warning "format" "prefix" } + (*tformatprintf0) ((*tformat_arg) ("%")); // { dg-warning "format" "prefix" } + (*tformatprintf1) ("%d", i); + (*tformatprintf1) ((*tformat_arg) ("%d"), i); + (*tformatprintf1) ("%"); // { dg-warning "format" "postfix" } + (*tformatprintf1) ((*tformat_arg) ("%")); // { dg-warning "format" "postfix" } + (*tformatprintf2) ("%d", i); + (*tformatprintf2) ((*tformat_arg) ("%d"), i); + (*tformatprintf2) ("%"); // { dg-warning "format" "nested" } + (*tformatprintf2) ((*tformat_arg) ("%")); // { dg-warning "format" "nested" } + (****tformatprintf3) ("%d", i); + (****tformatprintf3) ((*tformat_arg) ("%d"), i); + (****tformatprintf3) ("%"); // { dg-warning "format" "nested 2" } + (****tformatprintf3) ((*tformat_arg) ("%")); // { dg-warning "format" "nested 2" } +} diff --git a/gcc/testsuite/g++.dg/warn/format3.C b/gcc/testsuite/g++.dg/warn/format3.C new file mode 100644 index 000000000..0bdaaee17 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/format3.C @@ -0,0 +1,12 @@ +// PR c++/13070 +// { dg-do compile } +// { dg-options "-Wformat" } + +extern "C" int printf (const char*, ...); + +int main() +{ + printf("%d\n", 1, 1); // { dg-warning "too many" "printf warning" } + return 0; +} + diff --git a/gcc/testsuite/g++.dg/warn/format4.C b/gcc/testsuite/g++.dg/warn/format4.C new file mode 100644 index 000000000..fa622fceb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/format4.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-Wformat=2" } + +extern "C" int printf (const char*, ...); + +void foo(int i) +{ + printf("Hello World %d!\n", i); + printf(&"Hello World %d!\n"[0], i); + printf(&"Hello World %d!\n"[6], i); + printf(&"Hello World %d!\n"[8]-2, i); + printf(&"Hello World %d!\n"[4]+2, i); +} diff --git a/gcc/testsuite/g++.dg/warn/forward-inner.C b/gcc/testsuite/g++.dg/warn/forward-inner.C new file mode 100644 index 000000000..dae99486a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/forward-inner.C @@ -0,0 +1,81 @@ +// Check that the compiler warns about inner-style forward declarations in +// contexts where they're not actually illegal, but merely useless. + +// Verify warnings for and within classes, and by extension, struct and union. +class C1; +class C1::C2; // { dg-error "does not name a type" } +class C1::C2::C3; // { dg-error "has not been declared" } + +class C1 { + public: + class C2; + class C2::C3; // { dg-error "does not name a type" } + class C2 { + public: + class C3; + class C3 { }; + class C3; + }; + class C2; + class C2::C3; // { dg-warning "declaration 'class C1::C2::C3' does not declare anything" } +}; + +class C1; +class C1::C2; // { dg-warning "declaration 'class C1::C2' does not declare anything" } +class C1::C2::C3; // { dg-warning "declaration 'class C1::C2::C3' does not declare anything" } + + +// Verify warnings for namespace scopes. +class N1::C4; // { dg-error "has not been declared" } +class N1::N2::C5; // { dg-error "has not been declared" } + +namespace N1 { + class C4; + class C4 { }; + class C4; + + class N2::C5; // { dg-error "has not been declared" } + namespace N2 { + class C5; + class C5 { }; + class C5; + } + class N2::C5; // { dg-warning "declaration 'class N1::N2::C5' does not declare anything" } +} + +class N1::C4; // { dg-warning "declaration 'class N1::C4' does not declare anything" } +class N1::N2::C5; // { dg-warning "declaration 'class N1::N2::C5' does not declare anything" } + + +// Verify that using declarations related to namespaces don't generate a +// warning. +using namespace N1; +using namespace N1::N2; + +namespace N3 { + using N1::C4; // Valid using declaration, no warning + using N1::N2::C5; // Valid using declaration, no warning +} + + +// Verify that explicit template instantiations, easy to confuse with +// forward declarations, don't generate a warning. +template +class TC6 { + public: + class TC7 { }; +}; + +template class TC6::TC7; // Valid explicit instantiation, no warning + + +// Verify that friend declarations, also easy to confuse with forward +// declrations, are similarly not warned about. +class C8 { + public: + class C9 { }; +}; +class C10 { + public: + friend class C8::C9; // Valid friend declaration, no warning +}; diff --git a/gcc/testsuite/g++.dg/warn/friend.C b/gcc/testsuite/g++.dg/warn/friend.C new file mode 100644 index 000000000..e7982896a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/friend.C @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options -Wredundant-decls } */ + +/* Test to see if spurious warnings about redundant + declarations are emiited because of the friend + declaration. */ + +class Foo +{ + friend void bar (Foo); +public: +}; + +extern void bar (Foo); diff --git a/gcc/testsuite/g++.dg/warn/huge-val1.C b/gcc/testsuite/g++.dg/warn/huge-val1.C new file mode 100644 index 000000000..2ddfae0c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/huge-val1.C @@ -0,0 +1,33 @@ +// PR c++/23139: HUGE_VAL definition should be accepted with -pedantic. +// Origin: Joseph Myers +// { dg-do link } +// { dg-options "-pedantic-errors" } + +#include + +double d = HUGE_VAL; +#ifdef HUGE_VALF +float f = HUGE_VALF; +#endif +#ifdef HUGE_VALL +long double l = HUGE_VALL; +#endif + +extern void link_failure (); + +int +main () +{ +#ifdef __GLIBC__ + if (HUGE_VAL != __builtin_huge_val ()) + link_failure (); +#ifdef HUGE_VALF + if (HUGE_VALF != __builtin_huge_valf ()) + link_failure (); +#endif +#ifdef HUGE_VALL + if (HUGE_VALL != __builtin_huge_vall ()) + link_failure (); +#endif +#endif +} diff --git a/gcc/testsuite/g++.dg/warn/if-empty-1.C b/gcc/testsuite/g++.dg/warn/if-empty-1.C new file mode 100644 index 000000000..b29a6cb92 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/if-empty-1.C @@ -0,0 +1,23 @@ +/* Test diagnostics for empty bodies in if / else. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wempty-body" } */ + +void +f (int x) +{ + if (x) + ; /* { dg-warning "suggest braces around empty body in an" } */ + if (x) + ; /* By design we don't warn in this case. */ + else + (void)0; + if (x) + (void)0; + else + ; /* { dg-warning "suggest braces around empty body in an" } */ + if (x) + (void)0; + else + (void)0; +} diff --git a/gcc/testsuite/g++.dg/warn/ignored_typedef.C b/gcc/testsuite/g++.dg/warn/ignored_typedef.C new file mode 100644 index 000000000..74586a81f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/ignored_typedef.C @@ -0,0 +1,22 @@ +// PR c++/23689 +// Test that malformed typedef's produce a compiler warning. + +typedef char valid_0; +typedef int valid_1; +typedef long valid_2; +typedef float valid_3; +typedef double valid_4; +typedef unsigned valid_5; +typedef int *valid_6; +typedef struct valid_7 {} valid_8; +typedef struct {} valid_9; +typedef int temp_0; typedef temp_0 valid_10; +struct temp_1 {}; typedef temp_1 valid_11; +union temp_2 {}; typedef temp_2 valid_12; +typedef void (*valid_13) (int); + +typedef struct invalid_0 {}; // { dg-warning "'typedef' was ignored" } +typedef class invalid_1 {}; // { dg-warning "'typedef' was ignored" } +typedef enum invalid_2 { INVALID_2 }; // { dg-warning "'typedef' was ignored" } +typedef enum { INVALID_3 }; // { dg-warning "'typedef' was ignored" } +typedef union invalid_4 {}; // { dg-warning "'typedef' was ignored" } diff --git a/gcc/testsuite/g++.dg/warn/implicit-typename1.C b/gcc/testsuite/g++.dg/warn/implicit-typename1.C new file mode 100644 index 000000000..2952e6fd0 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/implicit-typename1.C @@ -0,0 +1,17 @@ +// The -pedantic option must be omitted to trigger the crash. +// { dg-do compile } +// { dg-options "" } + +// PR c++/7982: Crash warning about implicit typename. +// The base class refers to another typename, while the +// name lookup finds a template. + +template struct X {}; + +template struct C { + typedef typename T::X X; +}; + +template struct A : public C { + typedef ::X X; +}; diff --git a/gcc/testsuite/g++.dg/warn/implicit-typename2.C b/gcc/testsuite/g++.dg/warn/implicit-typename2.C new file mode 100644 index 000000000..2bd83cffa --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/implicit-typename2.C @@ -0,0 +1,12 @@ +// { dg-do compile } + +// Origin: Wolfgang Bangerth + +// PR c++/11039: Implicit typename warning in friend class declaration. + +template struct X { + struct Y { + struct Z {}; + }; + friend struct Y::Z; +}; diff --git a/gcc/testsuite/g++.dg/warn/implicit-typename3.C b/gcc/testsuite/g++.dg/warn/implicit-typename3.C new file mode 100644 index 000000000..9b1ea8cfc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/implicit-typename3.C @@ -0,0 +1,12 @@ +// { dg-do compile } + +// Origin: Wolfgang Bangerth + +// PR c++/11039: Implicit typename warning in friend class declaration. + +template struct X { + struct Y { + struct Z {}; + }; + template friend struct Y::Z f(U); +}; diff --git a/gcc/testsuite/g++.dg/warn/incomplete1.C b/gcc/testsuite/g++.dg/warn/incomplete1.C new file mode 100644 index 000000000..26cfe2eae --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/incomplete1.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Contributed by Brian Gaeke; public domain. + +// 5 If the object being deleted has incomplete class type at the +// point of deletion and the complete class has a non-trivial +// destructor or a deallocation function, the behavior is undefined. + +// (But the deletion does not constitute an ill-formed program. So the +// program should nevertheless compile, but it should give a warning.) + +class A; // { dg-warning "forward declaration of 'struct A'" "" } + +A *a; // { dg-warning "'a' has incomplete type" "" } + +int +main (int argc, char **argv) +{ + delete a; // { dg-warning "delete" "warn" } + // { dg-message "note" "note" { target *-*-* } 19 } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/incomplete2.C b/gcc/testsuite/g++.dg/warn/incomplete2.C new file mode 100644 index 000000000..30be26749 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/incomplete2.C @@ -0,0 +1,13 @@ +// PR c++/33501 +// { dg-do compile } + +class A; // { dg-error "forward declaration" } + +int f (A); // { dg-error "initializing" } +const A &make (); + +int +main () +{ + return f (make ()); // { dg-error "invalid use of incomplete type" } +} diff --git a/gcc/testsuite/g++.dg/warn/inline1.C b/gcc/testsuite/g++.dg/warn/inline1.C new file mode 100644 index 000000000..24836e744 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/inline1.C @@ -0,0 +1,23 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Dec 2002 + +// PR 4803. Used inline functions must have a definition. + +inline void Foo1 (); // { dg-warning "inline function" "" } +inline void Bar1 (); +template inline void Foo2(T); // { dg-warning "inline function" "" } +template inline void Bar2(T); + +void Baz () +{ + Foo1 (); + Foo2 (1); + + Bar1 (); + Bar2 (1); +} + +inline void Bar1 () {} +template inline void Bar2(T) {} diff --git a/gcc/testsuite/g++.dg/warn/inline2.C b/gcc/testsuite/g++.dg/warn/inline2.C new file mode 100644 index 000000000..0f5f78af1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/inline2.C @@ -0,0 +1,20 @@ +// PR c++/21627 + +template +struct TPL +{ + TPL (){} + ~TPL (){} + void method () {} +}; + +template <> TPL::TPL (); +template <> TPL::~TPL (); +template <> void TPL::method (); + +void Foo () +{ + TPL i; + i.method (); +} + diff --git a/gcc/testsuite/g++.dg/warn/main-2.C b/gcc/testsuite/g++.dg/warn/main-2.C new file mode 100644 index 000000000..d38ef8e09 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/main-2.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// Make sure that the type of f1 does not change +// after the error of main about not returning +// int. +// From Pekka Vuorela +// PR c++/23229 + +void f1(); + +void +main() /* { dg-error "must return" } */ +{ + f1(); +} + +void f1() +{ +} + diff --git a/gcc/testsuite/g++.dg/warn/main-3.C b/gcc/testsuite/g++.dg/warn/main-3.C new file mode 100644 index 000000000..eb462f4ba --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/main-3.C @@ -0,0 +1,7 @@ +// PR c++/29735 +// { dg-do compile } + +int __attribute__ ((vector_size (8))) main () // { dg-error "must return" } +{ + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/main-4.C b/gcc/testsuite/g++.dg/warn/main-4.C new file mode 100644 index 000000000..ad2dd7098 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/main-4.C @@ -0,0 +1,5 @@ +// This pattern is used by a lot of autoconf scripts, so don't +// complain about it unless -pedantic. +// { dg-options "" } + +int main () { main (); return 0; } diff --git a/gcc/testsuite/g++.dg/warn/main.C b/gcc/testsuite/g++.dg/warn/main.C new file mode 100644 index 000000000..ebf92177b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/main.C @@ -0,0 +1,11 @@ +// { dg-do compile } + +// Origin: Donald W. Gillies + +// PR c++/4494: Incorrect diagnostics about return type of main. + +typedef int int_t; + +int_t main() { + +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-1.C b/gcc/testsuite/g++.dg/warn/miss-format-1.C new file mode 100644 index 000000000..a35cd9ca9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-1.C @@ -0,0 +1,43 @@ +/* Test for warnings for missing format attributes. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ +/* { dg-options "-Wmissing-format-attribute -Wno-abi" { target arm_eabi } } */ +/* VxWorks does not provide vscanf, either in kernel or RTP mode. */ +/* { dg-error "not declared" "" { target { *-*-solaris2.8 *-*-vxworks* alpha*-dec-osf* } } 26 } */ + +#include +#include + +void +foo (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vprintf (fmt, ap); /* { dg-warning "candidate" "printf attribute warning" } */ + va_end (ap); +} + +void +bar (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vscanf (fmt, ap); /* { dg-warning "candidate" "scanf attribute warning" { xfail *-*-solaris2.8 *-*-vxworks* alpha*-dec-osf* } } */ + va_end (ap); +} + +__attribute__((__format__(__printf__, 1, 2))) void +foo2 (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vprintf (fmt, ap); + va_end (ap); +} + +void +vfoo (const char *fmt, va_list arg) +{ + vprintf (fmt, arg); /* { dg-warning "candidate" "printf attribute warning 2" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-2.C b/gcc/testsuite/g++.dg/warn/miss-format-2.C new file mode 100644 index 000000000..bd7f11ba8 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-2.C @@ -0,0 +1,17 @@ +/* Test for warnings for missing format attributes. Don't warn if no + relevant parameters for a format attribute; see c/1017. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ + +#include +#include + +void +foo (int i, ...) +{ + va_list ap; + va_start (ap, i); + vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */ + va_end (ap); +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-3.C b/gcc/testsuite/g++.dg/warn/miss-format-3.C new file mode 100644 index 000000000..d131d1511 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-3.C @@ -0,0 +1,27 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ +/* { dg-options "-Wmissing-format-attribute -Wno-abi" { target arm_eabi } } */ + +#include + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +void +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + noattr_t na1 = na; + noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */ + attr_t a1 = na; + attr_t a2 = a; + + vnoattr_t vna1 = vna; + vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */ + vattr_t va1 = vna; + vattr_t va2 = va; +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-4.C b/gcc/testsuite/g++.dg/warn/miss-format-4.C new file mode 100644 index 000000000..73db0d50b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-4.C @@ -0,0 +1,33 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ +/* { dg-options "-Wmissing-format-attribute -Wno-abi" { target arm_eabi } } */ + +#include + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +void +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + noattr_t na1, na2; + attr_t a1, a2; + + vnoattr_t vna1, vna2; + vattr_t va1, va2; + + na1 = na; + na2 = a; /* { dg-warning "candidate" "assignment warning" } */ + a1 = na; + a2 = a; + + vna1 = vna; + vna2 = va; /* { dg-warning "candidate" "assignment warning" } */ + va1 = vna; + va1 = va; +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-5.C b/gcc/testsuite/g++.dg/warn/miss-format-5.C new file mode 100644 index 000000000..cbc27b5e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-5.C @@ -0,0 +1,49 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ +/* { dg-options "-Wmissing-format-attribute -Wno-abi" { target arm_eabi } } */ + +#include + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +noattr_t +foo1 (noattr_t na, attr_t a, int i) +{ + if (i) + return na; + else + return a; /* { dg-warning "candidate" "return type warning" } */ +} + +attr_t +foo2 (noattr_t na, attr_t a, int i) +{ + if (i) + return na; + else + return a; +} + +vnoattr_t +foo3 (vnoattr_t vna, vattr_t va, int i) +{ + if (i) + return vna; + else + return va; /* { dg-warning "candidate" "return type warning" } */ +} + +vattr_t +foo4 (vnoattr_t vna, vattr_t va, int i) +{ + if (i) + return vna; + else + return va; +} diff --git a/gcc/testsuite/g++.dg/warn/miss-format-6.C b/gcc/testsuite/g++.dg/warn/miss-format-6.C new file mode 100644 index 000000000..f78dbdfa1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/miss-format-6.C @@ -0,0 +1,32 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-format-attribute" } */ +/* { dg-options "-Wmissing-format-attribute -Wno-abi" { target arm_eabi } } */ + +#include + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +extern void foo1 (noattr_t); +extern void foo2 (attr_t); +extern void foo3 (vnoattr_t); +extern void foo4 (vattr_t); + +void +foo (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + foo1 (na); + foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */ + foo2 (na); + foo2 (a); + + foo3 (vna); + foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */ + foo4 (vna); + foo4 (va); +} diff --git a/gcc/testsuite/g++.dg/warn/missing-field-init-1.C b/gcc/testsuite/g++.dg/warn/missing-field-init-1.C new file mode 100644 index 000000000..f28418f0c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/missing-field-init-1.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wextra -Wno-missing-field-initializers" } */ + +struct s { int a, b, c; }; +struct s s1 = { 1, 2, 3 }; +struct s s2 = { 1, 2 }; /* { dg-bogus "missing initializer" } */ +struct s s3[] = { { 1, 2 }, { 4, 5 } }; /* { dg-bogus "missing initializer" } */ +struct s s4[] = { 1, 2, 3, 4, 5 }; /* { dg-bogus "missing initializer" } */ +struct s s5[] = { 1, 2, 3, 4, 5, 6 }; diff --git a/gcc/testsuite/g++.dg/warn/missing-field-init-2.C b/gcc/testsuite/g++.dg/warn/missing-field-init-2.C new file mode 100644 index 000000000..7f6ec060f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/missing-field-init-2.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-Wmissing-field-initializers" } */ + +struct s { int a, b, c; }; +struct s s1 = { 1, 2, 3 }; +struct s s2 = { 1, 2 }; /* { dg-warning "(missing initializer)|(near initialization)" } */ +struct s s3[] = { { 1, 2 }, { 4, 5 } }; /* { dg-warning "(missing initializer)|(near initialization)" } */ +struct s s4[] = { 1, 2, 3, 4, 5 }; /* { dg-warning "(missing initializer)|(near initialization)" } */ +struct s s5[] = { 1, 2, 3, 4, 5, 6 }; diff --git a/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-1.C b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-1.C new file mode 100644 index 000000000..489930211 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-1.C @@ -0,0 +1,13 @@ +/* PR c/19978 : Test for duplicated warnings (unary operators). */ +/* { dg-do compile } */ +/* { dg-options "-Woverflow" } */ + +#include + +int +g (void) +{ + return - - - - -INT_MIN; /* { dg-bogus "integer overflow in expression.*integer overflow in expression" } */ + /* { dg-warning "integer overflow in expression" "" { target *-*-* } 10 } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-2.C b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-2.C new file mode 100644 index 000000000..863016bfd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-2.C @@ -0,0 +1,12 @@ +/* PR c/19978 : Test for duplicated warnings (binary operators). */ +/* { dg-do compile } */ +/* { dg-options "-Woverflow" } */ + +#include + +int +g1 (void) +{ + return INT_MAX + 1 - INT_MAX; /* { dg-bogus "integer overflow in expression.*integer overflow in expression" } */ + /* { dg-warning "integer overflow in expression" "" { target *-*-* } 10 } */ +} diff --git a/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C new file mode 100644 index 000000000..afb4e517f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/multiple-overflow-warn-3.C @@ -0,0 +1,12 @@ +/* PR 30465 : Test for duplicated warnings in a conversion. */ +/* { dg-do compile } */ +/* { dg-options "-Woverflow" } */ + +short int +g (void) +{ + short int wc = ((short int)1 << 31) - 1; /* { dg-bogus "overflow .* overflow" } */ + /* { dg-warning "overflow" "" { target *-*-* } 8 } */ + return wc; +} + diff --git a/gcc/testsuite/g++.dg/warn/new1.C b/gcc/testsuite/g++.dg/warn/new1.C new file mode 100644 index 000000000..b50b2c354 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/new1.C @@ -0,0 +1,3 @@ +void f() { + new int[0]; // { dg-bogus "zero" } +} diff --git a/gcc/testsuite/g++.dg/warn/no-write-strings.C b/gcc/testsuite/g++.dg/warn/no-write-strings.C new file mode 100644 index 000000000..c5d48de37 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/no-write-strings.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options -Wno-write-strings } + +int main() +{ + char* p = "Asgaard"; +} diff --git a/gcc/testsuite/g++.dg/warn/noeffect2.C b/gcc/testsuite/g++.dg/warn/noeffect2.C new file mode 100644 index 000000000..451e0382a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect2.C @@ -0,0 +1,20 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 18 Aug 2003 +// Origin PR 11945 gerald@pfeifer.com + +// PR 11945 inconsistent warnings + +extern "C" void FormatDisk(); + template + struct C { + C(){ FormatDisk(), 0; } // { dg-warning "right operand of comma" "" } + }; + template struct C; // { dg-message "instantiated" } + template + void f() { FormatDisk(), 0; } // { dg-warning "right operand of comma" "" } + template void f (); // { dg-message "instantiated" } +void g() { FormatDisk(), 0; } // { dg-warning "right operand of comma" "" } + diff --git a/gcc/testsuite/g++.dg/warn/noeffect4.C b/gcc/testsuite/g++.dg/warn/noeffect4.C new file mode 100644 index 000000000..966716bbc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect4.C @@ -0,0 +1,88 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 2 Sep 2003 + +// PR 12037. + +struct X +{ + int operator+(int); + int operator-(int); + int operator*(int); + int operator/(int); + int operator%(int); + int operator>>(int); + int operator<<(int); + int operator&(int); + int operator|(int); + int operator^(int); + int operator&&(int); + int operator||(int); + int operator==(int); + int operator!=(int); + int operator<(int); + int operator<=(int); + int operator>(int); + int operator>=(int); + int operator*(); + int operator!(); + int operator~(); + int operator++(); + int operator--(); + int operator++(int); + int operator--(int); + int operator()(); + int operator,(int); + X *operator->(); + operator int () const; + int m; + virtual ~X (); + X &Foo (); +}; +struct Y : X +{ +}; + +template void Foo (X &x) +{ + x + I; + x - I; + x * I; + x / I; + x % I; + x >> I; + x << I; + x & I; + x | I; + x && I; + x || I; + x == I; + x != I; + x < I; + x <= I; + x > I; + x >= I; + *x; + !x; + ~x; + x++; + x--; + ++x; + --x; + x (); + x, I; + x->m; + static_cast (x); + dynamic_cast (x); + reinterpret_cast (x.Foo ()); // { dg-error "invalid cast" } + const_cast (x.Foo ()); // { dg-warning "not used" } + + reinterpret_cast (&x);// { dg-warning "no effect" "" } + const_cast (x); // { dg-warning "no effect" "" } + sizeof (x++); // { dg-warning "no effect" "" } + __alignof__ (x++); // { dg-warning "no effect" "" } +} + +template void Foo<4> (X&); // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/noeffect5.C b/gcc/testsuite/g++.dg/warn/noeffect5.C new file mode 100644 index 000000000..f0f4e7410 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect5.C @@ -0,0 +1,8 @@ +/* PR middle-end/13325 */ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ + +void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); +void f (void *dest, const void *src) { + memcpy (dest, src, 0); +} diff --git a/gcc/testsuite/g++.dg/warn/noeffect6.C b/gcc/testsuite/g++.dg/warn/noeffect6.C new file mode 100644 index 000000000..ca6baba81 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect6.C @@ -0,0 +1,14 @@ +// { dg-options "-Wall" } +// PR c++/15083 + +extern "C" int printf(const char*,...); +struct Counter { + Counter(){printf("Hello World.\n");} +}; +template< typename T > +void resetData() { + new Counter(); +} +int main() { + resetData(); +} diff --git a/gcc/testsuite/g++.dg/warn/noeffect7.C b/gcc/testsuite/g++.dg/warn/noeffect7.C new file mode 100644 index 000000000..4aca2496c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect7.C @@ -0,0 +1,8 @@ +// PR c++/8057 +// Don't give a "statement has no effect" warning when declaring a +// template, only when instantiating it. +// { dg-do compile } +// { dg-options "-Wunused" } +struct Y { static int i; }; +template class X { X() { Y::i; }; }; +class Z { Z() { Y::i; }; }; // { dg-warning "no effect" } diff --git a/gcc/testsuite/g++.dg/warn/noeffect8.C b/gcc/testsuite/g++.dg/warn/noeffect8.C new file mode 100644 index 000000000..48edfdea6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect8.C @@ -0,0 +1,15 @@ +// PR c++/26696, 28996 +// { dg-do compile } +// { dg-options "-Waddress" } + +struct A +{ + static void f() {} +}; + +int main() +{ + A a; + a.f; // { dg-warning "not call" } + A().f; // { dg-warning "not call" } +} diff --git a/gcc/testsuite/g++.dg/warn/nonnull1.C b/gcc/testsuite/g++.dg/warn/nonnull1.C new file mode 100644 index 000000000..46de7e931 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/nonnull1.C @@ -0,0 +1,16 @@ +// Test that "nonnull" attribute works for C++. +// Origin: Joseph Myers +// { dg-do compile } +// { dg-options "-Wall" } + +// The "nonnull" attribute is thoroughly tested for C, so here we +// simply test that it works at all, as at one point the relevant +// checking code was only called for C. + +extern void f (char *) __attribute__((nonnull)); + +void +g () +{ + f (0); // { dg-warning "null" "null argument" } +} diff --git a/gcc/testsuite/g++.dg/warn/noreturn-1.C b/gcc/testsuite/g++.dg/warn/noreturn-1.C new file mode 100644 index 000000000..17375d42e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-1.C @@ -0,0 +1,71 @@ +// Test that noreturn attributes are properly set. +// Origin: Kaveh Ghazi 2002-06-18. +// { dg-do compile } +// { dg-options "-Wall -O2" } + +#include + +int foo1 (int i) +{ + switch (i) + { + case 1: + case 2: + return i; + } + abort(); +} + +int foo2 (int i) +{ + switch (i) + { + case 1: + case 2: + return i; + } + std::abort(); +} + +int foo3 (int i) +{ + switch (i) + { + case 1: + case 2: + return i; + } + exit(1); +} + +int foo4 (int i) +{ + switch (i) + { + case 1: + case 2: + return i; + } + std::exit(1); +} + +void __attribute__ ((__noreturn__)) foo5 () +{ + abort(); +} + +void __attribute__ ((__noreturn__)) foo6 () +{ + std::abort(); +} + +void __attribute__ ((__noreturn__)) foo7 () +{ + exit(1); +} + +void __attribute__ ((__noreturn__)) foo8 () +{ + std::exit(1); +} + diff --git a/gcc/testsuite/g++.dg/warn/noreturn-2.C b/gcc/testsuite/g++.dg/warn/noreturn-2.C new file mode 100644 index 000000000..3b18e1dbc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-2.C @@ -0,0 +1,4 @@ +// { dg-options "-Wall" } + +template +int f (T t) { } // { dg-warning "no return" } diff --git a/gcc/testsuite/g++.dg/warn/noreturn-3.C b/gcc/testsuite/g++.dg/warn/noreturn-3.C new file mode 100644 index 000000000..828935c12 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-3.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Origin: stip@mathematik.uni-ulm.de +// Andrew Pinski + +// PR c++/13106: No return warning when return type is a dependent type. + +template T dummy() { } + +int main() { + dummy(); +} diff --git a/gcc/testsuite/g++.dg/warn/noreturn-4.C b/gcc/testsuite/g++.dg/warn/noreturn-4.C new file mode 100644 index 000000000..7ef76cc5b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-4.C @@ -0,0 +1,13 @@ +// PR c++/30988 +// { dg-do compile } +// { dg-options "-O2 -Wall" } + +void f (const char *) __attribute__ ((noreturn)); + +template struct A +{ + int g () + { + f (__FUNCTION__); + } +}; diff --git a/gcc/testsuite/g++.dg/warn/noreturn-5.C b/gcc/testsuite/g++.dg/warn/noreturn-5.C new file mode 100644 index 000000000..77d4890df --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-5.C @@ -0,0 +1,15 @@ +// PR c++/30988 +// { dg-do compile } +// { dg-options "-O2 -Wall" } + +void f (const char *) __attribute__ ((noreturn)); +void f (int) __attribute__ ((noreturn)); +void f (double) __attribute__ ((noreturn)); + +template struct A +{ + int g () + { + f ((T) 0); + } +}; diff --git a/gcc/testsuite/g++.dg/warn/noreturn-6.C b/gcc/testsuite/g++.dg/warn/noreturn-6.C new file mode 100644 index 000000000..fdbc42516 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-6.C @@ -0,0 +1,13 @@ +// PR c++/30988 +// { dg-do compile } +// { dg-options "-O2 -Wall" } + +void f (const char *); + +template struct A +{ + int g () + { + f (__FUNCTION__); + } // { dg-warning "no return statement in function returning non-void" } +}; diff --git a/gcc/testsuite/g++.dg/warn/noreturn-7.C b/gcc/testsuite/g++.dg/warn/noreturn-7.C new file mode 100644 index 000000000..a869b7016 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-7.C @@ -0,0 +1,15 @@ +// PR c++/30988 +// { dg-do compile } +// { dg-options "-O2 -Wall" } + +void f (const char *) __attribute__ ((noreturn)); +void f (int); +void f (double) __attribute__ ((noreturn)); + +template struct A +{ + int g () + { + f ((T) 0); + } // { dg-warning "no return statement in function returning non-void" } +}; diff --git a/gcc/testsuite/g++.dg/warn/null4.C b/gcc/testsuite/g++.dg/warn/null4.C new file mode 100644 index 000000000..6aa4a097f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/null4.C @@ -0,0 +1,55 @@ +// PR c++/24745 : warnings for NULL constant. +// { dg-do compile } +// { dg-options "-Wpointer-arith -Wconversion " } + +#include + +int foo (void) +{ + if (NULL == 1) return -1; // { dg-warning "NULL used in arithmetic" } + if (NULL > NULL) return -1; // { dg-warning "NULL used in arithmetic" } + if (NULL < NULL) return -1; // { dg-warning "NULL used in arithmetic" } + if (NULL >= 0) return -1; // { dg-warning "NULL used in arithmetic" } + if (NULL <= 0) return -1; // { dg-warning "NULL used in arithmetic" } + // Adding to the NULL pointer, which has no specific type, should + // result in a warning; the type of the resulting expression is + // actually "int", not a pointer type. + if (NULL + 1) return -1; // { dg-warning "NULL used in arithmetic" } + if (1 + NULL) return -1; // { dg-warning "NULL used in arithmetic" } + return 0; +} + +int *ip; + +struct S {}; +typedef int S::*SPD; +typedef void (S::*SPF)(void); +SPD spd; +SPF spf; + +int bar (void) +{ + if (NULL) return -1; + if (!NULL) return -1; + if (!NULL == 1) return -1; + if (NULL || NULL) return -1; + if (!NULL && NULL) return -1; + if (NULL == NULL) return -1; + if (NULL != NULL) return -1; + if (NULL == 0) return -1; + if (NULL != 0) return -1; + // Subtraction of pointers is vaild, so using NULL is OK. + if (ip - NULL) return -1; + if (NULL - NULL) return -1; + // Comparing NULL with a pointer-to-member is OK. + if (NULL == spd) return -1; + if (spd == NULL) return -1; + if (NULL != spd) return -1; + if (spd != NULL) return -1; + if (NULL == spf) return -1; + if (spf == NULL) return -1; + if (NULL != spf) return -1; + if (spf != NULL) return -1; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/oldcast1.C b/gcc/testsuite/g++.dg/warn/oldcast1.C new file mode 100644 index 000000000..26c0a5c4d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/oldcast1.C @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-options "-ansi -pedantic-errors -Wold-style-cast" } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Dec 2001 + +// PR 5089. old style cast to void should be permitted (think assert) + +void foo () +{ + int i; + float f = (float)i; // { dg-warning "use of old-style cast" "" } + + (void)i; +} + diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-1.C b/gcc/testsuite/g++.dg/warn/overflow-warn-1.C new file mode 100644 index 000000000..22c512a4f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/overflow-warn-1.C @@ -0,0 +1,128 @@ +/* Test for diagnostics for constant overflow. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-fpermissive" } */ + +#include + +enum e { + E0 = INT_MAX, + /* Unsigned overflow wraps around. */ + E1 = UINT_MAX + 1, + /* Overflow in an unevaluated part of an expression is OK (example + in the standard). */ + E2 = 2 || 1 / 0, /* { dg-bogus "warning: division by zero" "" { xfail *-*-* } 14 } */ + E3 = 1 / 0, /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E3' is not an integer constant|not a constant expression" "enum error" { target *-*-* } 15 } */ + /* But as in DR#031, the 1/0 in an evaluated subexpression means the + whole expression violates the constraints. */ + E4 = 0 * (1 / 0), /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */ + E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 21 } */ + /* Again, overflow in evaluated subexpression. */ + E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 24 } */ + /* A cast does not constitute overflow in conversion. */ + E7 = (char) INT_MAX +}; + +struct s { + int a; + int : 0 * (1 / 0); /* { dg-warning "division by zero" } */ + int : 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 33 } */ +}; + +void +f (void) +{ + /* This expression is not required to be a constant expression, so + it should just involve undefined behavior at runtime. */ + int c = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ +} + +/* This expression is neither required to be constant. */ +static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ + + +// Test for overflow in null pointer constant. +void *n = 0; +/* The first two of these involve overflow, so are not null pointer + constants. The third has the overflow in an unevaluated + subexpression, so is a null pointer constant. */ +void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ +/* { dg-warning "invalid conversion from 'int' to 'void" "null" { target *-*-* } 54 } */ +void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */ +/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 56 } */ +void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */ + +void +g (int i) +{ + switch (i) + { + case 0 * (1/0): /* { dg-warning "division by zero" } */ + ; + case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 67 } */ + ; + } +} + +int +h (void) +{ + return INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ +} + +int +h1 (void) +{ + return INT_MAX + 1 - INT_MAX; /* { dg-warning "integer overflow in expression" } */ +} + +void fuc (unsigned char); +void fsc (signed char); + +void +h2 (void) +{ + fsc (SCHAR_MAX + 1); + fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (UCHAR_MAX); + fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fuc (-1); + fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (SCHAR_MIN); + fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ +} + +void fui (unsigned int); +void fsi (signed int); + +int si; +unsigned ui; + +void +h2i (int x) +{ + /* For some reason, we only give certain warnings for implicit + conversions among values of the same precision with -Wconversion, + while we don't give others at all. */ + fsi ((unsigned)INT_MAX + 1); + si = (unsigned)INT_MAX + 1; + si = x ? (unsigned)INT_MAX + 1 : 1; + fsi ((unsigned)INT_MAX + 2); + si = (unsigned)INT_MAX + 2; + si = x ? (unsigned)INT_MAX + 2 : 1; + fsi (UINT_MAX); + si = UINT_MAX; + fui (-1); + ui = -1; + ui = x ? -1 : 1U; + fui (INT_MIN); + ui = INT_MIN; + ui = x ? INT_MIN : 1U; +} diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-3.C b/gcc/testsuite/g++.dg/warn/overflow-warn-3.C new file mode 100644 index 000000000..d88c87a53 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/overflow-warn-3.C @@ -0,0 +1,130 @@ +/* Test for diagnostics for constant overflow. Test with -pedantic. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-fpermissive -pedantic" } */ + +#include + +enum e { + E0 = INT_MAX, + /* Unsigned overflow wraps around. */ + E1 = UINT_MAX + 1, + /* Overflow in an unevaluated part of an expression is OK (example + in the standard). */ + E2 = 2 || 1 / 0, /* { dg-bogus "warning: division by zero" "" { xfail *-*-* } 14 } */ + E3 = 1 / 0, /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E3' is not an integer constant|not a constant expression" "enum error" { target *-*-* } 15 } */ + /* But as in DR#031, the 1/0 in an evaluated subexpression means the + whole expression violates the constraints. */ + E4 = 0 * (1 / 0), /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */ + E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 21 } */ + /* Again, overflow in evaluated subexpression. */ + E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 24 } */ + /* A cast does not constitute overflow in conversion. */ + E7 = (char) INT_MAX +}; + +struct s { + int a; + int : 0 * (1 / 0); /* { dg-warning "division by zero" } */ + int : 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 33 } */ +}; + +void +f (void) +{ + /* This expression is not required to be a constant expression, so + it should just involve undefined behavior at runtime. */ + int c = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ + +} + +/* This expression is neither required to be constant. */ +static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ + + +// Test for overflow in null pointer constant. +void *n = 0; +/* The first two of these involve overflow, so are not null pointer + constants. The third has the overflow in an unevaluated + subexpression, so is a null pointer constant. */ +void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ +/* { dg-warning "invalid conversion from 'int' to 'void" "null" { target *-*-* } 55 } */ + +void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */ +/* { dg-warning "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 58 } */ +void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */ + +void +g (int i) +{ + switch (i) + { + case 0 * (1/0): /* { dg-warning "division by zero" } */ + ; + case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */ + /* { dg-warning "overflow in constant expression" "constant" { target *-*-* } 69 } */ + ; + } +} + +int +h (void) +{ + return INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ +} + +int +h1 (void) +{ + return INT_MAX + 1 - INT_MAX; /* { dg-warning "integer overflow in expression" } */ +} + +void fuc (unsigned char); +void fsc (signed char); + +void +h2 (void) +{ + fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fuc (-1); + fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (SCHAR_MIN); + fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ +} + +void fui (unsigned int); +void fsi (signed int); + +int si; +unsigned ui; + +void +h2i (int x) +{ + /* For some reason, we only give certain warnings for implicit + conversions among values of the same precision with -Wconversion, + while we don't give others at all. */ + fsi ((unsigned)INT_MAX + 1); + si = (unsigned)INT_MAX + 1; + si = x ? (unsigned)INT_MAX + 1 : 1; + fsi ((unsigned)INT_MAX + 2); + si = (unsigned)INT_MAX + 2; + si = x ? (unsigned)INT_MAX + 2 : 1; + fsi (UINT_MAX); + si = UINT_MAX; + fui (-1); + ui = -1; + ui = x ? -1 : 1U; + fui (INT_MIN); + ui = INT_MIN; + ui = x ? INT_MIN : 1U; +} diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-4.C b/gcc/testsuite/g++.dg/warn/overflow-warn-4.C new file mode 100644 index 000000000..374d29428 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/overflow-warn-4.C @@ -0,0 +1,133 @@ +/* Test for diagnostics for constant overflow. Test with -pedantic-errors. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +#include + +enum e { + E0 = INT_MAX, + /* Unsigned overflow wraps around. */ + E1 = UINT_MAX + 1, + /* Overflow in an unevaluated part of an expression is OK (example + in the standard). */ + E2 = 2 || 1 / 0, /* { dg-bogus "warning: division by zero" "" { xfail *-*-* } } */ + E3 = 1 / 0, /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E3' is not an integer constant|not a constant expression" "enum error" { target *-*-* } 15 } */ + /* But as in DR#031, the 1/0 in an evaluated subexpression means the + whole expression violates the constraints. */ + E4 = 0 * (1 / 0), /* { dg-warning "division by zero" } */ + /* { dg-error "enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */ + E5 = INT_MAX + 1, /* { dg-warning "integer overflow in expression" } */ + /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 21 } */ + /* { dg-error "enumerator value for 'E5' is not an integer constant" "enum error" { target *-*-* } 21 } */ + /* Again, overflow in evaluated subexpression. */ + E6 = 0 * (INT_MAX + 1), /* { dg-warning "integer overflow in expression" } */ + /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 25 } */ + /* { dg-error "enumerator value for 'E6' is not an integer constant" "enum error" { target *-*-* } 25 } */ + /* A cast does not constitute overflow in conversion. */ + E7 = (char) INT_MAX +}; + +struct s { + int a; + int : 0 * (1 / 0); /* { dg-warning "division by zero" } */ + int : 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ + /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 35 } */ + /* { dg-error "bit-field .* width not an integer constant" "" { target *-*-* } 35 } */ +}; + +void +f (void) +{ + /* This expression is not required to be a constant expression, so + it should just involve undefined behavior at runtime. */ + int c = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ + +} + +/* This expression is neither required to be constant. */ +static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ + + +// Test for overflow in null pointer constant. +void *n = 0; +/* The first two of these involve overflow, so are not null pointer + constants. The third has the overflow in an unevaluated + subexpression, so is a null pointer constant. */ +void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */ +/* { dg-error "invalid conversion from 'int' to 'void" "null" { target *-*-* } 58 } */ + +void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */ +/* { dg-error "invalid conversion from 'int' to 'void*'" "null" { xfail *-*-* } 61 } */ +void *r = (1 ? 0 : INT_MAX+1); /* { dg-bogus "integer overflow in expression" "" { xfail *-*-* } } */ + +void +g (int i) +{ + switch (i) + { + case 0 * (1/0): /* { dg-warning "division by zero" } */ + ; + case 1 + 0 * (INT_MAX + 1): /* { dg-warning "integer overflow in expression" } */ + /* { dg-error "overflow in constant expression" "constant" { target *-*-* } 72 } */ + ; + } +} + +int +h (void) +{ + return INT_MAX + 1; /* { dg-warning "integer overflow in expression" } */ +} + +int +h1 (void) +{ + return INT_MAX + 1 - INT_MAX; /* { dg-warning "integer overflow in expression" } */ +} + +void fuc (unsigned char); +void fsc (signed char); + +void +h2 (void) +{ + fsc (SCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (SCHAR_MIN - 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (UCHAR_MAX); /* { dg-warning "overflow in implicit constant conversion" } */ + fsc (UCHAR_MAX + 1); /* { dg-warning "overflow in implicit constant conversion" } */ + fuc (-1); + fuc (UCHAR_MAX + 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (SCHAR_MIN); + fuc (SCHAR_MIN - 1); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ + fuc (-UCHAR_MAX); /* { dg-warning "large integer implicitly truncated to unsigned type" } */ +} + +void fui (unsigned int); +void fsi (signed int); + +int si; +unsigned ui; + +void +h2i (int x) +{ + /* For some reason, we only give certain warnings for implicit + conversions among values of the same precision with -Wconversion, + while we don't give others at all. */ + fsi ((unsigned)INT_MAX + 1); + si = (unsigned)INT_MAX + 1; + si = x ? (unsigned)INT_MAX + 1 : 1; + fsi ((unsigned)INT_MAX + 2); + si = (unsigned)INT_MAX + 2; + si = x ? (unsigned)INT_MAX + 2 : 1; + fsi (UINT_MAX); + si = UINT_MAX; + fui (-1); + ui = -1; + ui = x ? -1 : 1U; + fui (INT_MIN); + ui = INT_MIN; + ui = x ? INT_MIN : 1U; +} diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-5.C b/gcc/testsuite/g++.dg/warn/overflow-warn-5.C new file mode 100644 index 000000000..bdfec4a6b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/overflow-warn-5.C @@ -0,0 +1,11 @@ +/* PR c/27273 */ +/* { dg-do compile } */ + +// This used to warn about "overflow in implicit constant conversion", +// which was wrong; 512 is never converted to unsigned char. Rather, an +// appropriate warning would be that the & expression always evaluates to 0 +// because of the limited range of unsigned char. + +unsigned char rx_async(unsigned char p) { + return p & 512; /* { dg-warning "" "" { xfail *-*-* } } */ +} diff --git a/gcc/testsuite/g++.dg/warn/overflow-warn-6.C b/gcc/testsuite/g++.dg/warn/overflow-warn-6.C new file mode 100644 index 000000000..6c7a28b3c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/overflow-warn-6.C @@ -0,0 +1,18 @@ +/* Test non-constant operands in overflowed expressions. */ +/* { dg-do compile } */ +/* { dg-options "-Woverflow" } */ + +#include + +int +h1 (int x) +{ + return x * (0 * (INT_MAX + 1)); /* { dg-warning "integer overflow in expression" } */ +} + +int +h2 (int x) +{ + return ((INT_MAX + 1) * 0) * x; /* { dg-warning "integer overflow in expression" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/pedantic1.C b/gcc/testsuite/g++.dg/warn/pedantic1.C new file mode 100644 index 000000000..2a4d05536 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pedantic1.C @@ -0,0 +1,11 @@ +// PR10032 +// { dg-options "-pedantic" } + +int main() { + goto label; // { dg-error "" } + + int temp = 1; // { dg-error "" } + + label: // { dg-error "" } + return 1; +} diff --git a/gcc/testsuite/g++.dg/warn/pedantic2.C b/gcc/testsuite/g++.dg/warn/pedantic2.C new file mode 100644 index 000000000..6c834162c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pedantic2.C @@ -0,0 +1,10 @@ +// { dg-options "-pedantic" } + +class foo +{ + foo() {}; + void bar() {}; + + foo(int) {};; // { dg-warning "extra" } + void bar(int) {};; // { dg-warning "extra" } +}; diff --git a/gcc/testsuite/g++.dg/warn/pmf1.C b/gcc/testsuite/g++.dg/warn/pmf1.C new file mode 100644 index 000000000..013c21b6d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pmf1.C @@ -0,0 +1,18 @@ +// { dg-do compile } + +// Origin: benko@sztaki.hu + +// PR c++/10496: Incorrect pointer to member function diagnostics +// for constant member functions. + +struct a +{ + int f() const; +}; + + +int +a::f() const +{ + int (a::* b)() const = &f; // { dg-error "&a::f" } +} diff --git a/gcc/testsuite/g++.dg/warn/pointer-integer-comparison.C b/gcc/testsuite/g++.dg/warn/pointer-integer-comparison.C new file mode 100644 index 000000000..c6b75a7fc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pointer-integer-comparison.C @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-fsyntax-only -fpermissive" } + +int foo (int i, void *p) +{ + if (i == p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 0; + else if (i != p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 1; +} + +int bar (int i, void *p) +{ + if (i < p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 0; + else if (i >= p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 1; +} + +int baz (int i, void *p) +{ + if (i <= p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 0; + else if (i > p) // { dg-warning "ISO C.. forbids comparison between pointer and integer" } + return 1; +} diff --git a/gcc/testsuite/g++.dg/warn/pr11159.C b/gcc/testsuite/g++.dg/warn/pr11159.C new file mode 100644 index 000000000..ed4107a23 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr11159.C @@ -0,0 +1,37 @@ +// PR c++/11159 : erroneous warning in copy ctor with virtual inheritance +// { dg-do compile } +// { dg-options "-Wall -Wextra" } +struct A +{ + A (); +}; + +struct B : virtual A +{ + B (); +}; + +struct C : virtual A +{ + C (); +}; + +struct D : B, C +{ + D (D const&){} +}; + +template +struct E : Base +{ + E (); + + E (E const &) + : Base () + { + }; +}; + +E foo; +E bar (foo); + diff --git a/gcc/testsuite/g++.dg/warn/pr11492.C b/gcc/testsuite/g++.dg/warn/pr11492.C new file mode 100644 index 000000000..d23595f2d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr11492.C @@ -0,0 +1,12 @@ +// PR11492 +// { dg-do compile } +// { dg-options "-Wsign-compare" } +int main( void ) +{ + unsigned int a; + unsigned char b; + for ( a = 0, b = 2; a > b * 1000; a++ ) /* { dg-bogus "comparison between signed and unsigned integer" } */ + { ; } + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/pr12242.C b/gcc/testsuite/g++.dg/warn/pr12242.C new file mode 100644 index 000000000..e858c5405 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr12242.C @@ -0,0 +1,57 @@ +// PR 12242: should warn about out-of-range int->enum conversions +// { dg-do compile } +// { dg-options "-Wconversion -fpermissive" } +enum X { A }; +enum Y { B, C, D }; + +void example () +{ + int i = 5; + X x; + Y y; + + x = 10; // { dg-warning "invalid conversion from .int. to .X." } + // { dg-warning "unspecified" "" { target *-*-* } 13 } + x = 1; // { dg-warning "invalid conversion from .int. to .X." } + x = C; // { dg-error "cannot convert .Y. to .X. in assignment" } + x = D; // { dg-error "cannot convert .Y. to .X. in assignment" } + y = A; // { dg-error "cannot convert .X. to .Y. in assignment" } + x = y; // { dg-error "cannot convert .Y. to .X. in assignment" } + x = i; // { dg-warning "invalid conversion from .int. to .X." } +} + +void foo () +{ + X a = static_cast (10); // { dg-warning "unspecified" } + X b = static_cast (0); + X c = static_cast (1); + X d = static_cast (2); // { dg-warning "unspecified" } + X f = static_cast ((int)A); + X g = static_cast (B); + X h = static_cast (C); + X e = static_cast (D); // { dg-warning "unspecified" } +} + +enum QEvent { x = 42 }; + +int bar() +{ + QEvent x = ( QEvent ) 42000; // { dg-warning "unspecified" } + return ( int ) x; +} + +enum W {a,b,c}; +enum Z {d,e,f,g}; +void bazz (int, int, int, int); + +void baz() { + int three = 3; + int four = 4; + bazz ( + W(three), + W(3), + Z(four), + Z(4) // { dg-warning "unspecified" } + ); +} + diff --git a/gcc/testsuite/g++.dg/warn/pr13358-2.C b/gcc/testsuite/g++.dg/warn/pr13358-2.C new file mode 100644 index 000000000..9ab8bbc41 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr13358-2.C @@ -0,0 +1,24 @@ +// PR c++/13358: g++ should accept a long long constant sans LL suffix +// if -Wno-long-long is in use. +// { dg-do compile } +// { dg-require-effective-target int32plus } +// { dg-options "-std=c++98 -pedantic-errors" } + + +void use_longlong () +{ + unsigned long long x1, x2, x3; // { dg-error "ISO C\\+\\+ 1998 does not support 'long long'" } + // make sure we error with hex, decimal and octal + x1 = 0x1b27da572ef3cd86; // { dg-error "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } + x2 = 1956772631100509574; // { dg-error "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } + x3 = 0154476645345674746606; // { dg-error "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } +} + +void use_longlong2 () +{ + unsigned long long x1, x2, x3; // { dg-error "ISO C\\+\\+ 1998 does not support 'long long'" } + // make sure we error with hex, decimal and octal + x1 = 0x1b27da572ef3cd86LL; // { dg-error "long long" } + x2 = 1956772631100509574LL; // { dg-error "long long" } + x3 = 0154476645345674746606LL; // { dg-error "long long" } +} diff --git a/gcc/testsuite/g++.dg/warn/pr13358-3.C b/gcc/testsuite/g++.dg/warn/pr13358-3.C new file mode 100644 index 000000000..f23e7d97e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr13358-3.C @@ -0,0 +1,24 @@ +// PR c++/13358: g++ should accept a long long constant sans LL suffix +// if -Wno-long-long is in use +// { dg-do compile } +// { dg-require-effective-target int32plus } +// { dg-options "-std=c++0x -pedantic-errors" } + + +void use_longlong () +{ + unsigned long long x1, x2, x3; + // make sure it's ok with hex, decimal and octal + x1 = 0x1b27da572ef3cd86; + x2 = 1956772631100509574; + x3 = 0154476645345674746606; +} + +void use_longlong2 () +{ + unsigned long long x1, x2, x3; + // make sure it's ok with hex, decimal and octal + x1 = 0x1b27da572ef3cd86LL; + x2 = 1956772631100509574LL; + x3 = 0154476645345674746606LL; +} diff --git a/gcc/testsuite/g++.dg/warn/pr13358-4.C b/gcc/testsuite/g++.dg/warn/pr13358-4.C new file mode 100644 index 000000000..b9a59ca62 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr13358-4.C @@ -0,0 +1,24 @@ +// PR c++/13358: g++ should accept a long long constant sans LL suffix +// if -Wno-long-long is in use. +// { dg-do compile } +// { dg-require-effective-target int32plus } +// { dg-options "-std=c++0x -pedantic-errors -Wlong-long" } + + +void use_longlong () +{ + unsigned long long x1, x2, x3; // { dg-warning "ISO C\\+\\+ 1998 does not support 'long long'" } + // make sure we warn with hex, decimal and octal + x1 = 0x1b27da572ef3cd86; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } + x2 = 1956772631100509574; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } + x3 = 0154476645345674746606; // { dg-warning "integer constant is too large for 'long' type" "long long" { target { llp64 || ilp32 } } } +} + +void use_longlong2 () +{ + unsigned long long x1, x2, x3; // { dg-warning "ISO C\\+\\+ 1998 does not support 'long long'" } + // make sure we warn with hex, decimal and octal + x1 = 0x1b27da572ef3cd86LL; // { dg-warning "long long" } + x2 = 1956772631100509574LL; // { dg-warning "long long" } + x3 = 0154476645345674746606LL; // { dg-warning "long long" } +} diff --git a/gcc/testsuite/g++.dg/warn/pr13358.C b/gcc/testsuite/g++.dg/warn/pr13358.C new file mode 100644 index 000000000..257616d2f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr13358.C @@ -0,0 +1,24 @@ +// PR c++/13358: g++ should accept a long long constant sans LL suffix +// if -Wno-long-long is in use. +// { dg-do compile } +// { dg-require-effective-target int32plus } +// { dg-options "-std=c++98 -Wno-long-long -pedantic-errors" } + + +void use_longlong () +{ + unsigned long long x1, x2, x3; + // make sure it's ok with hex, decimal and octal + x1 = 0x1b27da572ef3cd86; + x2 = 1956772631100509574; + x3 = 0154476645345674746606; +} + +void use_longlong2 () +{ + unsigned long long x1, x2, x3; + // make sure it's ok with hex, decimal and octal + x1 = 0x1b27da572ef3cd86LL; + x2 = 1956772631100509574LL; + x3 = 0154476645345674746606LL; +} diff --git a/gcc/testsuite/g++.dg/warn/pr15774-1.C b/gcc/testsuite/g++.dg/warn/pr15774-1.C new file mode 100644 index 000000000..efd4daeb6 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr15774-1.C @@ -0,0 +1,15 @@ +// { dg-do compile { target { { i?86-*-* x86_64-*-* } && ilp32 } } } +// Test that an new declartion with different attributes then old one fail. +extern void foo (int); // { dg-error "ambiguates old declaration" } + +void +bar (void) +{ + foo (1); +} + +void __attribute__((stdcall)) foo (int i) // { dg-error "new declaration" } +{ +} + + diff --git a/gcc/testsuite/g++.dg/warn/pr15774-2.C b/gcc/testsuite/g++.dg/warn/pr15774-2.C new file mode 100644 index 000000000..f890b7af7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr15774-2.C @@ -0,0 +1,15 @@ +// { dg-do compile { target { { i?86-*-* x86_64-*-* } && ilp32 } } } +// Test that old declaration is used, if new one has no attributes. +extern void __attribute__((stdcall)) foo (int); + +void +bar (void) +{ + foo (1); +} + +void foo (int i) +{ +} + + diff --git a/gcc/testsuite/g++.dg/warn/pr16302.C b/gcc/testsuite/g++.dg/warn/pr16302.C new file mode 100644 index 000000000..a6f1a4574 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr16302.C @@ -0,0 +1,76 @@ +// PR 16302 +/* { dg-do compile } */ +/* { dg-options "-Wlogical-op" } */ +void bar (int); +int +foo (int argc, char *argv[]) +{ + if (argc != 1 || argc != 2) return 1; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + if (argc < 0 && argc > 10) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + if (argc || !argc) return 1; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + if (argc && !argc) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc != 1 || argc != 2); /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + bar (argc < 0 && argc > 10); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc || !argc); /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + bar (argc && !argc); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc != 1 || argc != 2) ? 1 : 0 ; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + return (argc < 0 && argc > 10) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc || !argc) ? 1 : 0; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + return (argc && !argc) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + + if (argc == 2 && argc == 1) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + if (argc < 0 && argc > 10) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + if (argc || !argc) return 1; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + if (argc && !argc) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc == 2 && argc == 1); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc < 0 && argc > 10); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc || !argc); /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + bar (argc && !argc); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc == 2 && argc == 1) ? 1 : 0 ; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc < 0 && argc > 10) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc || !argc) ? 1 : 0; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + return (argc && !argc) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + + if (argc == 2 && argc == 1) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + if (argc < 0 && argc > 10) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + if (!argc || argc) return 1; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + if (!argc && argc) return 1; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc == 2 && argc == 1); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (argc < 0 && argc > 10); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + bar (!argc || argc); /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + bar (!argc && argc); /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc == 2 && argc == 1) ? 1 : 0 ; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (argc < 0 && argc > 10) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + return (!argc || argc) ? 1 : 0; /* { dg-warning "'or' of collectively exhaustive tests is always true" } */ + return (!argc && argc) ? 1 : 0; /* { dg-warning "'and' of mutually exclusive tests is always false" } */ + + return 0; +} + +int +foo2 (int argc) +{ + if (5 != 1 || 5 != 2) return 1; + if (5 < 0 && 5 > 10) return 1; + if (1 || 0) return 1; + if (0 && 1) return 1; + if (2 || !2) return 1; + if (2 && !2) return 1; + if (!(!2) || !(2)) return 1; + if (!(!2) && !(2)) return 1; + bar (5 != 1 || 5 != 2); + bar (5 < 0 && 5 > 10); + bar (1 || 0); + bar (0 && 1); + bar (2 || !2); + bar (2 && !2); + return (5 != 1 || 5 != 2) ? 1 : 0 ; + return (5 < 0 && 5 > 10) ? 1 : 0; + return (1 || 0) ? 1 : 0 ; + return (0 && 1) ? 1 : 0; + return (2 || !2) ? 1 : 0; + return (2 && !2) ? 1 : 0; + + return 0; +} + diff --git a/gcc/testsuite/g++.dg/warn/pr21983.C b/gcc/testsuite/g++.dg/warn/pr21983.C new file mode 100644 index 000000000..0108169ea --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr21983.C @@ -0,0 +1,7 @@ +// PR c++/21983 +// { dg-do compile } + +struct B { virtual void foo () = 0; }; +struct D1 : public virtual B { virtual void foo () {} }; +struct D2 : public virtual B { virtual void foo () {} }; +struct D : public D1, public D2 { }; // { dg-error "no unique final overrider" } diff --git a/gcc/testsuite/g++.dg/warn/pr23075.C b/gcc/testsuite/g++.dg/warn/pr23075.C new file mode 100644 index 000000000..e5b1b483d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr23075.C @@ -0,0 +1,9 @@ +// PR c/23075 +// { dg-do compile } +// { dg-options "-O2 -Wreturn-type" } + +int +foo (void) +{ + return; // { dg-error "with no value" } +} // { dg-warning "no return statement" } diff --git a/gcc/testsuite/g++.dg/warn/pr26785.C b/gcc/testsuite/g++.dg/warn/pr26785.C new file mode 100644 index 000000000..f3984d58e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr26785.C @@ -0,0 +1,10 @@ +// PR 26785 +// { dg-do compile } +// { dg-options "-fshow-column" } + +class foo { + foo::foo // { dg-error "3:extra qualification" } + (int a, + int b, + int c); +}; diff --git a/gcc/testsuite/g++.dg/warn/pr28943.C b/gcc/testsuite/g++.dg/warn/pr28943.C new file mode 100644 index 000000000..046312c0e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr28943.C @@ -0,0 +1,15 @@ +// PR c++/28943 void and non-void in conditional expression +// { dg-do compile } +// { dg-options "" } + +void debug (const char * string) +{ + return; +} + +int f() +{ + ( true == false ? 0 : debug ("Some string")); // { dg-error "third operand .* type 'void'.* second operand is neither a throw-expression nor of type 'void'" } + ( true == false ? debug ("Some string") : 0 ); // { dg-error "second operand .* type 'void'.* third operand is neither a throw-expression nor of type 'void'" } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/pr30551-2.C b/gcc/testsuite/g++.dg/warn/pr30551-2.C new file mode 100644 index 000000000..8334746a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr30551-2.C @@ -0,0 +1,6 @@ +// PR 30551 -Wmain is enabled by -pedantic/-pedantic-errors. +// { dg-do compile } +// { dg-options "-pedantic-errors" } +// { dg-skip-if "-Wmain not enabled with -pedantic on SPU" { spu-*-* } } +int main(char a) {} /* { dg-error "first argument of .*main.* should be .int." } */ +/* { dg-error "main.* takes only zero or two arguments" "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/g++.dg/warn/pr30551.C b/gcc/testsuite/g++.dg/warn/pr30551.C new file mode 100644 index 000000000..6d7f662c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr30551.C @@ -0,0 +1,6 @@ +// PR 30551 -Wmain is enabled by default. +// { dg-do compile } +// { dg-options "" } +// { dg-skip-if "-Wmain not enabled on SPU" { spu-*-* } } +int main(char a) {} /* { dg-warning "first argument of .*main.* should be .int." } */ +/* { dg-warning "main.* takes only zero or two arguments" "" { target *-*-* } 5 } */ diff --git a/gcc/testsuite/g++.dg/warn/pr30636.C b/gcc/testsuite/g++.dg/warn/pr30636.C new file mode 100644 index 000000000..32ce6edbd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr30636.C @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds" } */ + +typedef char one_buffer[512]; +static one_buffer emergency_buffer[4]; + +void free_exception (void *vptr) +{ + char *base = (char *) &emergency_buffer[0][0]; + char *ptr = (char *) vptr; + if (ptr >= base && ptr < base + sizeof (emergency_buffer)) /* { dg-bogus "subscript" } */ + { + /* Do something. */ + __builtin_exit (0); + } +} + diff --git a/gcc/testsuite/g++.dg/warn/pr31246-2.C b/gcc/testsuite/g++.dg/warn/pr31246-2.C new file mode 100644 index 000000000..c9a4cae7e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr31246-2.C @@ -0,0 +1,9 @@ +// PR 31246 +// { dg-do compile } +// { dg-options "-Wunreachable-code" } +#include + +int* get_ptr(void* ptr) +{ + return new(ptr) int(); +} diff --git a/gcc/testsuite/g++.dg/warn/pr31246.C b/gcc/testsuite/g++.dg/warn/pr31246.C new file mode 100644 index 000000000..a96dc96c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr31246.C @@ -0,0 +1,10 @@ +// PR 31246 +// { dg-do compile } +// { dg-options "-Wunreachable-code -D_GLIBCXX_DEBUG" } +// { dg-xfail-if "lack of weak symbols" { alpha*-dec-osf* } } +#include + +int main() +{ + std::vector::iterator a; +} diff --git a/gcc/testsuite/g++.dg/warn/pr33160.C b/gcc/testsuite/g++.dg/warn/pr33160.C new file mode 100644 index 000000000..e463e2dfd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr33160.C @@ -0,0 +1,12 @@ +// PR 33160 +// { dg-do compile } +// { dg-options "-Wall -Wextra -Wpointer-arith -pedantic -Wconversion" } + +typedef int __attribute__((mode(pointer))) intptr_t; +int foo(void) +{ + intptr_t t = 0; + if (t != ((intptr_t)__null)) t = 1; + return 0; +} + diff --git a/gcc/testsuite/g++.dg/warn/pr33738.C b/gcc/testsuite/g++.dg/warn/pr33738.C new file mode 100644 index 000000000..e84fece13 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr33738.C @@ -0,0 +1,26 @@ +// { dg-do run } +// { dg-options "-O2 -Wtype-limits -fstrict-enums" } +extern void link_error (void); + +enum Alpha { + ZERO = 0, ONE, TWO, THREE +}; + +Alpha a2; + +int m1 = -1; +int GetM1() { + return m1; +} + +int main() { + a2 = static_cast(GetM1()); + if (a2 == -1) { // { dg-warning "always false due" } + link_error (); + } + if (-1 == a2) { // { dg-warning "always false due" } + link_error (); + } + return 0; +} + diff --git a/gcc/testsuite/g++.dg/warn/pr34985.C b/gcc/testsuite/g++.dg/warn/pr34985.C new file mode 100644 index 000000000..56437509d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr34985.C @@ -0,0 +1,9 @@ +/* PR34985: Warning "defined but not used" despite __attribute__((__used__)) */ +/* { dg-do compile } */ +/* { dg-options "-Wall -Wextra -O2" } */ +static void xxyyzz (void); +static void __attribute__((__used__)) xxyyzz(void) +{ +} + +/* { dg-final { scan-assembler "xxyyzz" } } */ diff --git a/gcc/testsuite/g++.dg/warn/pr35602.C b/gcc/testsuite/g++.dg/warn/pr35602.C new file mode 100644 index 000000000..66a569b3d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr35602.C @@ -0,0 +1,28 @@ +// PR 35602 Bogus warning with -Wsign-conversion +// { dg-do compile } +// { dg-options "-Wconversion -Wsign-conversion" } +struct c +{ + ~c(); + c(); +}; + +int + +main(const int, + const char * const * const) +{ + c x[0UL][0UL] = // { dg-bogus "warning: conversion to .long unsigned int. from .long int. may change the sign of the result" } + { + }; + + c y[0UL] = + { + }; + + int z[0ul][0UL] = + { + }; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/pr35635.C b/gcc/testsuite/g++.dg/warn/pr35635.C new file mode 100644 index 000000000..66ade8b28 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr35635.C @@ -0,0 +1,89 @@ +/* PR 35635 */ +/* { dg-do compile } */ +/* { dg-options "-Wconversion -Wsign-conversion" } */ + +struct unsigned_bit { + unsigned int x:1; +} unsigned_bit; +struct signed_bit { + int x:1; +} signed_bit; +int bar; +int bar2; + +void func1() +{ + /* The result of boolean operators fits in unsiged int:1, thus do + not warn. */ + unsigned_bit.x = (bar != 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar == 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar <= 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar >= 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar < 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar > 0); /* { dg-bogus "conversion" } */ + unsigned_bit.x = !bar; /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar || bar2); /* { dg-bogus "conversion" } */ + unsigned_bit.x = (bar && bar2); /* { dg-bogus "conversion" } */ + + /* Both branches of ? fit in the destination, thus do not warn. */ + unsigned_bit.x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */ + unsigned_bit.x = bar != 0 ? 1.0 : 0.0; /* { dg-bogus "conversion" } */ + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + unsigned_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */ + unsigned_bit.x = bar != 0 ? 0 : -1; /* { dg-warning "conver" } */ +} + +void func2() +{ + signed char schar_x; + + /* Both branches of ? fit in the destination, thus do not warn. */ + schar_x = bar != 0 ? 1 : 0; /* { dg-bogus "conversion" } */ + schar_x = bar != 0 ? 2.0 : 10; /* { dg-bogus "conversion" } */ + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + schar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */ + schar_x = bar != 0 ? (signed char) 1024: -1024; /* { dg-warning "conversion" } */ +} + + + +void func3() +{ + unsigned char uchar_x; + + /* Both branches of ? fit in the destination, thus do not warn. */ + uchar_x = bar != 0 ? 1 : 0; + uchar_x = bar != 0 ? 2.0 : 10; + + /* At least one branch of ? does not fit in the destination, thus + warn. */ + uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */ + uchar_x = bar != 0 + ? (unsigned char) 1024 + : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */ +} + +void func4() +{ + signed_bit.x = -1; /* { dg-bogus "conversion" } */ + signed_bit.x = bar != 0 ? -1.0 : 0.0; /* { dg-bogus "conversion" } */ + signed_bit.x = bar != 0 ? -1 : 0; /* { dg-bogus "conversion" } */ + + signed_bit.x = 1; /* { dg-warning "conversion" } */ + signed_bit.x = (bar != 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar == 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar <= 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar >= 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar < 0); /* { dg-warning "conversion" } */ + signed_bit.x = (bar > 0); /* { dg-warning "conversion" } */ + signed_bit.x = !bar; /* { dg-warning "conversion" } */ + signed_bit.x = (bar || bar2); /* { dg-warning "conversion" } */ + signed_bit.x = (bar && bar2); /* { dg-warning "conversion" } */ + signed_bit.x = bar != 0 ? 1 : 0; /* { dg-warning "conversion" } */ + signed_bit.x = bar != 0 ? 2 : 0; /* { dg-warning "conversion" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/pr35711.C b/gcc/testsuite/g++.dg/warn/pr35711.C new file mode 100644 index 000000000..653269c0e --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr35711.C @@ -0,0 +1,8 @@ +// PR 35711 +// { dg-do compile } +// { dg-options "-Wcast-qual" } + +int* foo (volatile int *p) +{ + return (int*)p; // { dg-warning "cast from type 'volatile int\\*' to type 'int\\*' casts away qualifiers" } +} diff --git a/gcc/testsuite/g++.dg/warn/pr36069.C b/gcc/testsuite/g++.dg/warn/pr36069.C new file mode 100644 index 000000000..efb35c257 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr36069.C @@ -0,0 +1,16 @@ +// PR c++/36069 Strange "warning: suggest parentheses around +// assignment used as truth value" with volatile/non volatile bools +// { dg-do compile } +// { dg-options "-Wparentheses" } +struct foo { + bool a; + volatile bool b,c; + foo() { a = b = c = false; } // { dg-bogus "parentheses" } +}; + +int main() { + bool a; + volatile bool b,c; + a = b = c = false; // { dg-bogus "parentheses" } + foo A; +} diff --git a/gcc/testsuite/g++.dg/warn/pr36921.C b/gcc/testsuite/g++.dg/warn/pr36921.C new file mode 100644 index 000000000..739366910 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr36921.C @@ -0,0 +1,27 @@ +/* PR 36921: comparison operator can be overloaded. Do not emit + warnings in such case. + { dg-do compile } + { dg-options "-Wparentheses" } +*/ +struct A {}; +A operator<(A, A) { return A(); } +A operator>(A, A) { return A(); } +A operator<=(A, A) { return A(); } +A operator>=(A, A) { return A(); } +A operator==(A, A) { return A(); } +A operator!=(A, A) { return A(); } + +int main() { + A() < A() < A(); // should not emit warning + 1 < 2 < 3; // { dg-warning "mathematical meaning" "parentheses" } + A() > A() > A(); // should not emit warning + 1 > 2 > 3; // { dg-warning "mathematical meaning" "parentheses" } + A() <= A() <= A(); // should not emit warning + 1 <= 2 <= 3; // { dg-warning "mathematical meaning" "parentheses" } + A() >= A() >= A(); // should not emit warning + 1 >= 2 >= 3; // { dg-warning "mathematical meaning" "parentheses" } + + A() == A() < A (); // { dg-warning "suggest parentheses" "parentheses" } + A() < A() != A (); // { dg-warning "suggest parentheses" "parentheses" } + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/pr36954.C b/gcc/testsuite/g++.dg/warn/pr36954.C new file mode 100644 index 000000000..92cea2f38 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr36954.C @@ -0,0 +1,23 @@ +// PR c++/36954 +// { dg-do compile } +// { dg-options "-Wlogical-op -Wextra -Wall" } + +template void Test() +{ + if ((1 == 2) || (true)) { + } + + if ((1 == 2) || (!false)) { + } + + if (false || true) { + } +} + + + +int main() { + if ((1 == 2) || (true)) { + } +} + diff --git a/gcc/testsuite/g++.dg/warn/pr36999.C b/gcc/testsuite/g++.dg/warn/pr36999.C new file mode 100644 index 000000000..ce2286efc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr36999.C @@ -0,0 +1,40 @@ +/* PR36999: Erroneous "does not declare anything" warnings. */ +/* { dg-do compile } */ + +class C1 { + public: class C2 { }; +}; + +void cf1 (class C1::C2, void*); // { dg-bogus "does not declare anything" } +void cf2 (void*, class C1::C2); +void cf3 (C1::C2, void*); + +namespace N { + +enum E1 { foo }; +enum E2 { bar }; + +template +class TC1 { }; + +template +class TC2 : public TC1 { }; + +} + +void +tcf1 (N::TC2 *arg1, // { dg-bogus "does not declare anything" } + N::TC2 *arg2, + N::TC2 *arg3) +{ +} + +void * +tcf2 (void *x) +{ + return (void *) + (N::TC2 *) // { dg-bogus "does not declare anything" } + (N::TC2 *) + (N::TC2 *) + x; +} diff --git a/gcc/testsuite/g++.dg/warn/pr5310.C b/gcc/testsuite/g++.dg/warn/pr5310.C new file mode 100644 index 000000000..48a60062f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr5310.C @@ -0,0 +1,11 @@ +// PR 5310 +// { dg-do compile } +// { dg-options "-pedantic -Wall -Wextra -Wpointer-arith -Wconversion" } +void foo (int); +void foo (long); + +void bar() +{ + foo ((int)__null); + foo ((long)__null); +} diff --git a/gcc/testsuite/g++.dg/warn/pr5645.C b/gcc/testsuite/g++.dg/warn/pr5645.C new file mode 100644 index 000000000..5ca61bdba --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr5645.C @@ -0,0 +1,32 @@ +// PR5645: gcc warns that pure virtual class not explicitly initialized. +// { dg-do compile } +// { dg-options "-Wall -Wextra" } + +class a { +public: + virtual int f() = 0; + virtual int g() = 0; +}; + +class b : public a { +public: + b(); + b(const b& c); + +protected: + int i; +}; + +b::b() {} + +b::b(const b& c) { // { dg-bogus "base class .class a. should be explicitly initialized in the copy constructor" } + i = c.i; +} + +struct X {}; + +struct Y : X +{ + Y (Y const&) {} +}; + diff --git a/gcc/testsuite/g++.dg/warn/pr8570.C b/gcc/testsuite/g++.dg/warn/pr8570.C new file mode 100644 index 000000000..608f4d6b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr8570.C @@ -0,0 +1,13 @@ +// PR c++/8570 +// { dg-do compile } +// { dg-options "" } +template +class X { // { dg-message "note: previous declaration .* used 2" } +public: + X() { } + +private: + template friend class X; // { dg-error "redeclared with 1 template parameter" } +}; + +X i; // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/warn/pr8715.C b/gcc/testsuite/g++.dg/warn/pr8715.C new file mode 100644 index 000000000..330c148bb --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr8715.C @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Wsign-compare" } */ + +int foo() +{ + unsigned char b = '1'; + + bool x = ~b; /* { dg-warning "promoted ~unsigned is always non-zero" } */ + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header1.C b/gcc/testsuite/g++.dg/warn/pragma-system_header1.C new file mode 100644 index 000000000..489761b5b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header1.C @@ -0,0 +1,10 @@ +// PR c++/30500 +// { dg-options "-Wconversion" } + +#include "pragma-system_header1.h" + +void f() +{ + g(); + h(); +} diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header1.h b/gcc/testsuite/g++.dg/warn/pragma-system_header1.h new file mode 100644 index 000000000..684c6bf12 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header1.h @@ -0,0 +1,7 @@ +#pragma GCC system_header + +template + int g() { double d = 0.1; return d; } + +template + T h() { double d = 0.1; return d; } diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header2.C b/gcc/testsuite/g++.dg/warn/pragma-system_header2.C new file mode 100644 index 000000000..a39bea721 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header2.C @@ -0,0 +1,17 @@ +// PR c++/30500 +// { dg-options "-Wconversion" } + +#include "pragma-system_header2.h" + + +void f() +{ + g(); + h(); +} + +// { dg-warning "conversion" "" { target *-*-* } 2 } +// { dg-warning "conversion" "" { target *-*-* } 5 } + +// I couldn't find another way to make this work. +// { dg-prune-output "In file included from" } diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header2.h b/gcc/testsuite/g++.dg/warn/pragma-system_header2.h new file mode 100644 index 000000000..aa4f0e94d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header2.h @@ -0,0 +1,5 @@ +template + int g() { double d = 0.1; return d; } + +template + T h() { double d = 0.1; return d; } diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header3.C b/gcc/testsuite/g++.dg/warn/pragma-system_header3.C new file mode 100644 index 000000000..a9255c9c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header3.C @@ -0,0 +1,9 @@ +// PR c++/32368 +// { dg-options "-Wall -O" } + +#include "pragma-system_header3.h" + +int main() +{ + return f(); +} diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header3.h b/gcc/testsuite/g++.dg/warn/pragma-system_header3.h new file mode 100644 index 000000000..e16f38f8a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header3.h @@ -0,0 +1,7 @@ +#pragma GCC system_header + +static inline int f() +{ + int i; + return i; +} diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header4.C b/gcc/testsuite/g++.dg/warn/pragma-system_header4.C new file mode 100644 index 000000000..898e10801 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header4.C @@ -0,0 +1,6 @@ +// PR c++/32256 +// { dg-options "-Wall" } + +#include "pragma-system_header4.h" + +void ok() { } diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header4.h b/gcc/testsuite/g++.dg/warn/pragma-system_header4.h new file mode 100644 index 000000000..c3abae0af --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header4.h @@ -0,0 +1,2 @@ +#pragma GCC system_header +int noreturn() { } diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header5.C b/gcc/testsuite/g++.dg/warn/pragma-system_header5.C new file mode 100644 index 000000000..771db3d7c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header5.C @@ -0,0 +1,10 @@ +// PR c++/36760 +// { dg-options "-Wextra" } + +#include "pragma-system_header5.h" + +void f() +{ + g(); + g(); +} diff --git a/gcc/testsuite/g++.dg/warn/pragma-system_header5.h b/gcc/testsuite/g++.dg/warn/pragma-system_header5.h new file mode 100644 index 000000000..5732e4afd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pragma-system_header5.h @@ -0,0 +1,3 @@ +#pragma GCC system_header + +template T g(); diff --git a/gcc/testsuite/g++.dg/warn/private1.C b/gcc/testsuite/g++.dg/warn/private1.C new file mode 100644 index 000000000..c42d6b7e3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/private1.C @@ -0,0 +1,16 @@ +// g++ should not complain about A having private [cd]tors. + +class A +{ + A(); + ~A(); +public: + int dummy(); // needed to get bogus warning + static A* get_A (); +}; + +A* A::get_A() +{ + static A a; + return &a; +} diff --git a/gcc/testsuite/g++.dg/warn/register-var-1.C b/gcc/testsuite/g++.dg/warn/register-var-1.C new file mode 100644 index 000000000..6cbd23e2c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/register-var-1.C @@ -0,0 +1,14 @@ +/* PR/18160 */ + +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ + +/* This should yield an error even without -pedantic. */ +/* { dg-options "-ansi" } */ + +void g(int *); + +void f(void) +{ + register int x __asm ("eax"); + g(&x); /* { dg-error "address of explicit register variable" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/register-var-2.C b/gcc/testsuite/g++.dg/warn/register-var-2.C new file mode 100644 index 000000000..28f5df0cf --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/register-var-2.C @@ -0,0 +1,14 @@ +/* PR/18160 */ + +/* { dg-do compile } */ + +/* This should yield an error even without -pedantic. */ +/* { dg-options "-Wall -W" } */ + +void g(int *); + +void f(void) +{ + register int x; + g(&x); /* { dg-warning "address requested for 'x', which is declared 'register'" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/return-reference.C b/gcc/testsuite/g++.dg/warn/return-reference.C new file mode 100644 index 000000000..83021900d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/return-reference.C @@ -0,0 +1,21 @@ +// { dg-do compile } + +const int* bar(); + +const int& +foo1() +{ + static int empty; + const int* x = bar(); + return (x ? *x : empty); // { dg-bogus ".*" "" { xfail *-*-* } } +} + +const int& +foo2() +{ + static int empty; + const int* x = bar(); + const int& r = (x ? *x : empty); + return (r); +} + diff --git a/gcc/testsuite/g++.dg/warn/return-reference2.C b/gcc/testsuite/g++.dg/warn/return-reference2.C new file mode 100644 index 000000000..190266215 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/return-reference2.C @@ -0,0 +1,21 @@ +// PR c++/26671 + +class A +{ +public: + int first; + int second; + +}; + +int &f() +{ + A a; // { dg-warning "local" } + return a.second; +} + +int &g() +{ + int ar[42]; // { dg-warning "local" } + return ar[20]; +} diff --git a/gcc/testsuite/g++.dg/warn/sentinel.C b/gcc/testsuite/g++.dg/warn/sentinel.C new file mode 100644 index 000000000..5f718f830 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/sentinel.C @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-Wall" } */ +extern void ex (int i, ...) __attribute__ ((__sentinel__(0))); + +void f() +{ + ex (1, 0); /* { dg-warning "missing sentinel in function call" "" } */ + ex (1, 0L); /* { dg-warning "missing sentinel in function call" "" } */ + ex (1, (void *)0); + ex (1, __null); /* { dg-bogus "sentinel" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/sequence-pt-1.C b/gcc/testsuite/g++.dg/warn/sequence-pt-1.C new file mode 100644 index 000000000..05eee82c1 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/sequence-pt-1.C @@ -0,0 +1,109 @@ +/* Test for sequence point warnings. */ +/* Origin: Michael Meeks in + , + adapted to a testcase by Joseph Myers . */ +/* { dg-do compile } */ +/* { dg-options "-Wsequence-point" } */ + +struct s +{ + int a; +}; + +extern int fn (int); +extern int fnb (int, int); +extern int fnc (int *); +extern int sprintf (char *, const char *, ...); + +typedef __SIZE_TYPE__ size_t; + +void +foo (int a, int b, int n, int p, int *ptr, struct s *sptr, + int *ap, int *bp, int **cp, char *ans, int (*fnp[8])(int)) +{ + int len; + + a = a++; /* { dg-warning "undefined" "sequence point warning" } */ + a = --a; /* { dg-warning "undefined" "sequence point warning" } */ + a = ++a + b; /* { dg-warning "undefined" "sequence point warning" } */ + a = a-- + b; /* { dg-warning "undefined" "sequence point warning" } */ + ap[n] = bp[n++]; /* { dg-warning "undefined" "sequence point warning" } */ + ap[--n] = bp[n]; /* { dg-warning "undefined" "sequence point warning" } */ + ap[++n] = bp[--n]; /* { dg-warning "undefined" "sequence point warning" } */ + cp[n][n] = cp[n][n]++; /* { dg-warning "undefined" "sequence point warning" } */ + cp[n][p] = cp[n][n++]; /* { dg-warning "undefined" "sequence point warning" } */ + *ptr++ = (size_t)ptr++; /* { dg-warning "undefined" "sequence point warning" } */ + sptr->a = sptr->a++; /* { dg-warning "undefined" "sequence point warning" } */ + sptr->a = (size_t)(sptr++); /* { dg-warning "undefined" "sequence point warning" } */ + *ptr++ = fn (*ptr); /* { dg-warning "undefined" "sequence point warning" } */ + a = b = a++; /* { dg-warning "undefined" "sequence point warning" } */ + b = a = --b; /* { dg-warning "undefined" "sequence point warning" } */ + a = 1 + (a = 1); /* { dg-warning "undefined" "sequence point warning" } */ + a = (a = b); /* { dg-warning "undefined" "sequence point warning" } */ + a = (a = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */ + a = (bp[a++] = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */ + a = b++ * b++; /* { dg-warning "undefined" "sequence point warning" } */ + a = fnb (b++, b++); /* { dg-warning "undefined" "sequence point warning" } */ + a = (*fnp[b++]) (b++); /* { dg-warning "undefined" "sequence point warning" } */ + a = (*fnp[b]) (b++); /* { dg-warning "undefined" "sequence point warning" } */ + a = (*fnp[b++]) (b); /* { dg-warning "undefined" "sequence point warning" } */ + *ap = fnc (ap++); /* { dg-warning "undefined" "sequence point warning" } */ + (a += b) + (a += n); /* { dg-warning "undefined" "sequence point warning" } */ + a = (b, b++) + (b++, b); /* { dg-warning "undefined" "sequence point warning" } */ + ap[a++] += a; /* { dg-warning "undefined" "sequence point warning" } */ + ap[a+=1] += a; /* { dg-warning "undefined" "sequence point warning" } */ + ap[a++] += a++; /* { dg-warning "undefined" "sequence point warning" } */ + ap[a+=1] += a++; /* { dg-warning "undefined" "sequence point warning" } */ + a = a++, b = a; /* { dg-warning "undefined" "sequence point warning" } */ + b = a, a = a++; /* { dg-warning "undefined" "sequence point warning" } */ + a = (b++ ? n : a) + b; /* { dg-warning "undefined" "sequence point warning" } */ + b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */ + b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */ + (a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */ + b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */ + (a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */ + a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */ + + a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = ! (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = - (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + (a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = (b++, b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = b++ && b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = b++ || b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = (b++ ? b++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */ + ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */ + *ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */ + + /* The following will be represented internally with a tree consisting of + many duplicated SAVE_EXPRs. This caused the previous version of the + sequence point warning code to fail by running out of virtual memory. */ + a = ((b & 1 ? 21 : 0) + | (b & 2 ? 22 : 0) + | (b & 3 ? 23 : 0) + | (b & 4 ? 24 : 0) + | (b & 5 ? 25 : 0) + | (b & 6 ? 26 : 0) + | (b & 7 ? 27 : 0) + | (b & 8 ? 28 : 0) + | (b & 9 ? 29 : 0) + | (b & 10 ? 30 : 0) + | (b & 11 ? 31 : 0) + | (b & 12 ? 32 : 0) + | (b & 13 ? 1 : 0) + | (b & 14 ? 2 : 0) + | (b & 15 ? 3 : 0) + | (b & 16 ? 4 : 0) + | (b & 17 ? 5 : 0) + | (b & 18 ? 6 : 0) + | (b & 19 ? 7 : 0) + | (b & 20 ? 8 : 0) + | (b & 21 ? 9 : 0)); +} diff --git a/gcc/testsuite/g++.dg/warn/sequence-pt-2.C b/gcc/testsuite/g++.dg/warn/sequence-pt-2.C new file mode 100644 index 000000000..9a4b618ea --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/sequence-pt-2.C @@ -0,0 +1,46 @@ +/* More sequence point warning tests */ +/* { dg-do compile } */ +/* { dg-options "-Wsequence-point" } */ + +struct s { struct s *nxt; int v; } q; + +int x[10]; + +int foo(int *p) +{ + int i = 0; + + /* Test general-lvalue sequence point warnings */ + (*p) = (*p)++; /* { dg-warning "undefined" "sequence point warning" } */ + p[3] = p[3]++; /* { dg-warning "undefined" "sequence point warning" } */ + p[i] = p[i]++; /* { dg-warning "undefined" "sequence point warning" } */ + x[3] = x[3]++; /* { dg-warning "undefined" "sequence point warning" } */ + q.nxt->nxt->v = q.nxt->nxt->v++; /* { dg-warning "undefined" "sequence point warning" } */ + + /* test expressions that appear elsewhere in the C grammar */ + + { int a = i-i++; (void)a;} /* { dg-warning "undefined" "sequence point warning" } */ + + if ((i-i++) != 0) /* { dg-warning "undefined" "sequence point warning" } */ + return i-i++; /* { dg-warning "undefined" "sequence point warning" } */ + + for (i-i++;;) /* { dg-warning "undefined" "sequence point warning" } */ + ; + + for (; (i-i++) != 0; ) /* { dg-warning "undefined" "sequence point warning" } */ + ; + + for (;;i-i++) /* { dg-warning "undefined" "sequence point warning" } */ + ; + + while ((i-i++) != 0) /* { dg-warning "undefined" "sequence point warning" } */ + ; + + do {} while ((i-i++) != 0); /* { dg-warning "undefined" "sequence point warning" } */ + + switch (i-i++) { /* { dg-warning "undefined" "sequence point warning" } */ + case 0: return 1; + } + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/sequence-pt-3.C b/gcc/testsuite/g++.dg/warn/sequence-pt-3.C new file mode 100644 index 000000000..58971ca18 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/sequence-pt-3.C @@ -0,0 +1,15 @@ +/* More sequence point warning tests */ +/* { dg-do compile } */ +/* { dg-options "-Wsequence-point" } */ + +void bar(int i, int j) +{ + return; +} + +void foo (int i) +{ + int a = i-i++; (void)a; /* { dg-warning "undefined" "sequence point warning" } */ + + bar (i--, i++); /* { dg-warning "undefined" "sequence point warning" } */ +} diff --git a/gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C b/gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C new file mode 100644 index 000000000..01d87be8b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/sequence-pt-pr17880.C @@ -0,0 +1,54 @@ +// PR 17880 +// { dg-do compile } +// { dg-options "-Wsequence-point" } + +int +foo (int x) +{ + unsigned int a; + int b; + + b = (a += 5) > a; // { dg-warning "undefined" "sequence point warning" } + b = (a += 5) + a == 10; // { dg-warning "undefined" "sequence point warning" } + b = (a -= 5) > a; // { dg-warning "undefined" "sequence point warning" } + b = (a -= 5) + a == 10; // { dg-warning "undefined" "sequence point warning" } + b = a-- > a; // { dg-warning "undefined" "sequence point warning" } + b = a-- + a == 10; // { dg-warning "undefined" "sequence point warning" } + b = ++a > a; // { dg-warning "undefined" "sequence point warning" } + b = ++a + a == 10; // { dg-warning "undefined" "sequence point warning" } + + if ((a += 5) > a) return -1; // { dg-warning "undefined" "sequence point warning" } + if ((a += 5) + a == 10) return -1; // { dg-warning "undefined" "sequence point warning" } + if ((a -= 5) > a) return -1; // { dg-warning "undefined" "sequence point warning" } + if ((a -= 5) + a == 10) return -1; // { dg-warning "undefined" "sequence point warning" } + if (a-- > a) return -1; // { dg-warning "undefined" "sequence point warning" } + if (a-- + a == 10) return -1; // { dg-warning "undefined" "sequence point warning" } + if (++a > a) return -1; // { dg-warning "undefined" "sequence point warning" } + if (++a + a == 10) return -1; // { dg-warning "undefined" "sequence point warning" } + do {} while ((a += 5) > a); // { dg-warning "undefined" "sequence point warning" } + while ((a += 5) > a); // { dg-warning "undefined" "sequence point warning" } + for ((a += 5) > a;;); // { dg-warning "undefined" "sequence point warning" } + for (b = (a += 5) > a;;); // { dg-warning "undefined" "sequence point warning" } + for (; (a += 5) > a;); // { dg-warning "undefined" "sequence point warning" } + for (;; b = (a += 5) > a); // { dg-warning "undefined" "sequence point warning" } + for (;; a++ + a++); // { dg-warning "undefined" "sequence point warning" } + if (a) a++ - a--; // { dg-warning "undefined" "sequence point warning" } + ((a +=5) > a) ? a : b; // { dg-warning "undefined" "sequence point warning" } + return (a++ - a--); // { dg-warning "undefined" "sequence point warning" } +} + +void bar (int i) +{ + int a = i++ - i++; // { dg-warning "undefined" "sequence point warning" } +} + +void baz (int i) +{ + switch (i++ + i++) // { dg-warning "undefined" "sequence point warning" } + { + case 1: + i++ - i++; // { dg-warning "undefined" "sequence point warning" } + case 2: + break; + } +} diff --git a/gcc/testsuite/g++.dg/warn/skip-1.C b/gcc/testsuite/g++.dg/warn/skip-1.C new file mode 100644 index 000000000..027c405d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/skip-1.C @@ -0,0 +1,17 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Check that we don't warn about code that will not be executed. +extern int f2(int); +void +f1(int i) +{ + f2(1 == 1 ? 0 : f2(i >> -10)); + f2(1 == 1 ? 0 : f2(i >> 128)); + f2(1 == 1 ? 0 : f2(i << -10)); + f2(1 == 1 ? 0 : f2(1 << 128)); + f2(1 != 1 ? f2(i >> -10) : 0); + f2(1 != 1 ? f2(i >> 128) : 0); + f2(1 != 1 ? f2(i << -10) : 0); + f2(1 != 1 ? f2(1 << 128) : 0); +} diff --git a/gcc/testsuite/g++.dg/warn/skip-2.C b/gcc/testsuite/g++.dg/warn/skip-2.C new file mode 100644 index 000000000..28f9049a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/skip-2.C @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +extern int f2(int); +extern void f3(); +void +f1(int i) +{ + if (1 == 1 || f2(i >> -10)) + f3(); + if (1 == 1 || f2(i >> 128)) + f3(); + if (1 == 1 || f2(i << -10)) + f3(); + if (1 == 1 || f2(i << 128)) + f3(); + if (1 == 1 || i < 0xffffffff) + f3(); + if (1 == 1 || i >= -0x80000000) + f3(); + if (1 == 0 && f2(i >> -10)) + f3(); + if (1 == 0 && f2(i >> 128)) + f3(); + if (1 == 0 && f2(i << -10)) + f3(); + if (1 == 0 && f2(i << 128)) + f3(); + if (1 == 0 && i < 0xffffffff) + f3(); + if (1 == 0 && i >= -0x80000000) + f3(); + if (1 == 1 && f2(i >> -10)) /* { dg-warning "shift count is negative" } */ + f3(); + if (1 == 0 || f2(i << -10)) /* { dg-warning "shift count is negative" } */ + f3(); +} diff --git a/gcc/testsuite/g++.dg/warn/string1.C b/gcc/testsuite/g++.dg/warn/string1.C new file mode 100644 index 000000000..2670f63d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/string1.C @@ -0,0 +1,18 @@ +// PR c++/35652 +// { dg-options "-O" } + +#include +int test() { + // blank line padding, could also be code... + // + // + // + // + // + // + // + // + // + std::string s = ""; + s += 'x' + "y"; // { dg-warning "bounds of constant string" } +} diff --git a/gcc/testsuite/g++.dg/warn/switch1.C b/gcc/testsuite/g++.dg/warn/switch1.C new file mode 100644 index 000000000..49c17e912 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/switch1.C @@ -0,0 +1,15 @@ +// { dg-do compile { target { int32plus } } } + +signed char sc; + +void +foo (void) +{ + switch (sc) + { + case 1: + case 2 * __SCHAR_MAX__ + 3: // { dg-warning "case label value exceeds maximum" } + case - 2 * __SCHAR_MAX__ - 1: // { dg-warning "case label value is less than minimum" } + break; + } +} diff --git a/gcc/testsuite/g++.dg/warn/template-1.C b/gcc/testsuite/g++.dg/warn/template-1.C new file mode 100644 index 000000000..04ea5ae32 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/template-1.C @@ -0,0 +1,15 @@ +//Origin: bangerth@dealii.org +//PR c++/11490 +//Since N is know at instantiation time, there +// should be no warning about comparision between +// unsinged and signed interegers. + +// { dg-do compile } +// { dg-options "-W" } + +template bool f() { + unsigned int i=0; + return i!=N; // { dg-bogus "signed and unsigned" } +} + +template bool f<2> (); diff --git a/gcc/testsuite/g++.dg/warn/translate-ice-1.C b/gcc/testsuite/g++.dg/warn/translate-ice-1.C new file mode 100644 index 000000000..22e103c29 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/translate-ice-1.C @@ -0,0 +1,45 @@ +// Test ICE in caching printable names for a function. +// { dg-options "-std=c++98 -pedantic -O2" } + +void g (int a) __attribute__((warning("g"))); +void g2 (int a, int *p); +static inline __attribute__((__always_inline__)) void +gg (int a) +{ + if (a == 0) + return g(a); // { dg-warning "attribute" } + __extension__ int v[a]; + return g2(a, v); +} + +void h (int a) __attribute__((warning("h"))); +void h2 (int a, int *p); +static inline __attribute__((__always_inline__)) void +hh (int a) +{ + if (a == 0) + return h(a); // { dg-warning "attribute" } + __extension__ int v[a]; + return h2(a, v); +} + +void i (int a) __attribute__((warning("i"))); +void i2 (int a, int *p); +static inline __attribute__((__always_inline__)) void +ii (int a) +{ + if (a == 0) + return i(a); // { dg-warning "attribute" } + __extension__ int v[a]; + return i2(a, v); +} + +void +f (void) +{ + long long l; // { dg-warning "long long" } + const char *p = __PRETTY_FUNCTION__; + gg(0); + hh(0); + ii(0); +} diff --git a/gcc/testsuite/g++.dg/warn/undefined1.C b/gcc/testsuite/g++.dg/warn/undefined1.C new file mode 100644 index 000000000..87fa3ec5a --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/undefined1.C @@ -0,0 +1,7 @@ +// PR 17256 + +inline static void f1(void); // { dg-warning "used but never" } +void g1(void) { if (0) { f1(); } } + +inline void f2(void); // { dg-warning "used but never" } +void g2(void) { if (0) { f2(); } } diff --git a/gcc/testsuite/g++.dg/warn/unit-1.C b/gcc/testsuite/g++.dg/warn/unit-1.C new file mode 100644 index 000000000..49bc23136 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/unit-1.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wuninitialized" } */ + +struct a { int mode; }; +int sys_msgctl (void) +{ + struct a setbuf; /* { dg-warning "'setbuf.mode' is used" "" { xfail *-*-* } } */ + return setbuf.mode; +} + diff --git a/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c b/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c new file mode 100644 index 000000000..fc14469c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/unused-result1-Werror.c @@ -0,0 +1,11 @@ +// PR 40614 +// { dg-options "-Werror=unused-result" } +/* { dg-message "some warnings being treated as errors" "" {target "*-*-*"} 0 } */ +class QByteArray { +public: + QByteArray(const QByteArray &); +}; +class QString { + QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result)); + void fooWarnHere() const { toLocal8Bit(); } // { dg-error "ignoring" } +}; diff --git a/gcc/testsuite/g++.dg/warn/unused-result1.C b/gcc/testsuite/g++.dg/warn/unused-result1.C new file mode 100644 index 000000000..466c99e7d --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/unused-result1.C @@ -0,0 +1,10 @@ +// PR c++/27371 + +class QByteArray { +public: + QByteArray(const QByteArray &); +}; +class QString { + QByteArray toLocal8Bit() const __attribute__ ((warn_unused_result)); + void fooWarnHere() const { toLocal8Bit(); } // { dg-warning "ignoring" "" { xfail *-*-* } } +}; diff --git a/gcc/testsuite/g++.dg/warn/var-args1.C b/gcc/testsuite/g++.dg/warn/var-args1.C new file mode 100644 index 000000000..9bd84a7dd --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/var-args1.C @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +#include + +void foo(int, ...) +{ + va_list va; + int i; + i = va_arg(va, int&); /* { dg-error "cannot receive objects" } */ +} + diff --git a/gcc/testsuite/g++.dg/warn/volatile1.C b/gcc/testsuite/g++.dg/warn/volatile1.C new file mode 100644 index 000000000..ac9dd4df3 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/volatile1.C @@ -0,0 +1,12 @@ +// PR c++/26577 + +struct A +{ + A(const A&); + A& operator=(const A&); + void baz() volatile; +}; +void A::baz() volatile +{ + *this; // { dg-warning "indirection will not access" } +} diff --git a/gcc/testsuite/g++.dg/warn/weak1.C b/gcc/testsuite/g++.dg/warn/weak1.C new file mode 100644 index 000000000..8a50030bc --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/weak1.C @@ -0,0 +1,22 @@ +// { dg-do run } +// { dg-require-weak "" } +// The PA HP-UX and Tru64 UNIX dynamic loaders don't support unsatisfied +// weak symbols. +// { dg-skip-if "No unsat" { alpha*-dec-osf* hppa*-*-hpux* } { "*" } { "" } } +// The darwin loader does, but they do need to exist at link time. +// { dg-skip-if "No link unsat" { *-*-darwin* } { "*" } { "" } } +// For kernel modules and static RTPs, the loader treats undefined weak +// symbols in the same way as undefined strong symbols. The test +// therefore fails to load, so skip it. +// { dg-skip-if "" { "*-*-vxworks*" && nonpic } "*" { "-non-static" } } + +extern void foo (void) __attribute__ ((weak)); + +int +main () +{ + if (&foo) + foo (); + + return 0; +} diff --git a/gcc/testsuite/g++.dg/warn/write-strings-default.C b/gcc/testsuite/g++.dg/warn/write-strings-default.C new file mode 100644 index 000000000..ee6b21718 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/write-strings-default.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// Test the default for -Wwrite-strings + +int main() +{ + char* p = "Asgaard"; // { dg-warning "deprecated" } +} diff --git a/gcc/testsuite/g++.dg/warn/write-strings.C b/gcc/testsuite/g++.dg/warn/write-strings.C new file mode 100644 index 000000000..73c814909 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/write-strings.C @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options -Wwrite-strings } + +int main() +{ + char* p = "Asgaard"; // { dg-warning "deprecated" } +} -- cgit v1.2.3