diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a3370c4c40bcd16008c6c667bf84240843b7a930..9595419ad8033ad34cf47cafcac3f99450d4b39f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2008-01-12 Doug Kwan <dougkwan@google.com> + + * c-decl.c: (grokdeclarator): Use OPT_Wignored_qualifiers + instead of OPT_Wreturn_type in warning due to ignored return type + qualifiers. + * c-opt.c (c_common_post_option): Add -Wignored-qualifiers to + options included in -Wextra. + * c.opt: New option -Wignored_qualifiers. + * doc/invoke.texi (Warning Options, -Wextra): Add new option + -Wignore_qualifiers. + (-Wignored-qualifiers): Document. + (-Wreturn-type): Remove description of functionality now handled + by -Wignored-qualifiers. + 2008-01-12 Eric Botcazou <ebotcazou@adacore.com> PR ada/33788 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 033ff2eec49af527a2f6f0106ff7d915e489c181..9237a75491a5513687cb9fba0eae8236d4d50760 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4526,7 +4526,7 @@ grokdeclarator (const struct c_declarator *declarator, if (VOID_TYPE_P (type) && really_funcdef) pedwarn ("function definition has qualified void return type"); else - warning (OPT_Wreturn_type, + warning (OPT_Wignored_qualifiers, "type qualifiers ignored on function return type"); type = c_build_qualified_type (type, type_quals); diff --git a/gcc/c-opts.c b/gcc/c-opts.c index 3c6219265cd593c8d8eb6aedd79eed1285ae8836..951118c51b53308afc44dfc5372f7efebe4df22a 100644 --- a/gcc/c-opts.c +++ b/gcc/c-opts.c @@ -1064,7 +1064,7 @@ c_common_post_options (const char **pfilename) /* -Wextra implies -Wtype-limits, -Wclobbered, -Wempty-body, -Wsign-compare, -Wmissing-field-initializers, -Wmissing-parameter-type - -Wold-style-declaration, and -Woverride-init, + -Wold-style-declaration, -Woverride-init and -Wignored-qualifiers but not if explicitly overridden. */ if (warn_type_limits == -1) warn_type_limits = extra_warnings; @@ -1082,6 +1082,8 @@ c_common_post_options (const char **pfilename) warn_old_style_declaration = extra_warnings; if (warn_override_init == -1) warn_override_init = extra_warnings; + if (warn_ignored_qualifiers == -1) + warn_ignored_qualifiers = extra_warnings; /* -Wpointer_sign is disabled by default, but it is enabled if any of -Wall or -pedantic are given. */ diff --git a/gcc/c.opt b/gcc/c.opt index 37c55bedadf6627647214e16ba27a8e8d8c1feb1..37045197bf18954496db1c3e76ef11db5311cc08 100644 --- a/gcc/c.opt +++ b/gcc/c.opt @@ -242,6 +242,10 @@ Warn about zero-length formats Wformat= C ObjC C++ ObjC++ Joined Warning +Wignored-qualifiers +C C++ Var(warn_ignored_qualifiers) Init(-1) Warning +Warn whenever type qualifiers are ignored. + Winit-self C ObjC C++ ObjC++ Var(warn_init_self) Warning Warn about variables which are initialized to themselves diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8a6c34135fdb3eccf4c09b45e1feecf4c8215aaf..c46c07251a4552dc188174993ca256b3a5d18d10 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2008-01-12 Doug Kwan <dougkwan@google.com> + + * decl.c: (grokdeclarator): Use OPT_Wignored_qualifiers + instead of OPT_Wreturn_type in warning due to ignored return type + qualifiers. + * pt.c: (tsubst_function_type): Use OPT_Wignored_qualifiers + instead of OPT_Wreturn_type in warning due to ignored return type + qualifiers. + 2008-01-08 Jakub Jelinek <jakub@redhat.com> PR c++/33890 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index f968e88c0c598e8440a5871c0539c50ed6579dc3..11a5c478fbe24c072bdc224a207cbea516f432e2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8018,7 +8018,7 @@ grokdeclarator (const cp_declarator *declarator, if (type_quals != TYPE_UNQUALIFIED) { if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) - warning (OPT_Wreturn_type, + warning (OPT_Wignored_qualifiers, "type qualifiers ignored on function return type"); /* We now know that the TYPE_QUALS don't apply to the decl, but to its return type. */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 9f87778fc441e1456cf53dd5dbfb2edf1fecc97c..f25f2c403049143eeba64fb8da4bc256607183a0 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8663,7 +8663,7 @@ tsubst_function_type (tree t, && in_decl != NULL_TREE && !TREE_NO_WARNING (in_decl) && (SCALAR_TYPE_P (return_type) || VOID_TYPE_P (return_type))) - warning (OPT_Wreturn_type, + warning (OPT_Wignored_qualifiers, "type qualifiers ignored on function return type"); /* Construct a new type node and return it. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 177e007db11fa0b76ab1352934a336659af19234..5e41ec30f51b97f95b3a65dc0c4935afbd5b81c3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -236,7 +236,7 @@ Objective-C and Objective-C++ Dialects}. -Werror -Werror=* @gol -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol -Wno-format-extra-args -Wformat-nonliteral @gol --Wformat-security -Wformat-y2k @gol +-Wformat-security -Wformat-y2k -Wignored-qualifiers @gol -Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol -Wimport -Wno-import -Winit-self -Winline @gol -Wno-int-to-pointer-cast -Wno-invalid-offsetof @gol @@ -2675,6 +2675,7 @@ name is still supported, but the newer name is more descriptive.) @gccoptlist{-Wclobbered @gol -Wempty-body @gol +-Wignored-qualifiers @gol -Wmissing-field-initializers @gol -Wmissing-parameter-type @r{(C only)} @gol -Wold-style-declaration @r{(C only)} @gol @@ -2864,6 +2865,19 @@ enabled by default and it is made into an error by Same as @option{-Wimplicit-int} and @option{-Wimplicit-function-declaration}. This warning is enabled by @option{-Wall}. +@item -Wignored-qualifiers +@opindex Wignored-qualifiers +@opindex Wno-ignored-qualifiers +Warn if the return type of a function has a type qualifier +such as @code{const}. For ISO C such a type qualifier has no effect, +since the value returned by a function is not an lvalue. +For C++, the warning is only emitted for scalar types or @code{void}. +ISO C prohibits qualified @code{void} return types on function +definitions, so such return types always receive a warning +even without this option. + +This warning is also enabled by @option{-Wextra}. + @item -Wmain @opindex Wmain Warn if the type of @samp{main} is suspicious. @samp{main} should be a @@ -2996,14 +3010,6 @@ return-value in a function whose return-type is not @code{void} without a value), and about a @code{return} statement with a expression in a function whose return-type is @code{void}. -Also warn if the return type of a function has a type qualifier -such as @code{const}. For ISO C such a type qualifier has no effect, -since the value returned by a function is not an lvalue. -For C++, the warning is only emitted for scalar types or @code{void}. -ISO C prohibits qualified @code{void} return types on function -definitions, so such return types always receive a warning -even without this option. - For C++, a function without return type always produces a diagnostic message, even when @option{-Wno-return-type} is specified. The only exceptions are @samp{main} and functions defined in system headers. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1c7ec62cac675cbef1e75482775b89c431014059..34b4ec1158026170f7b03bac9cc9006b1324f2e1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-01-12 Doug Kwan <dougkwan@google.com> + + * gcc.dg/qual-return-1.c: Add -Wignored-qualifiers. + * g++.dg/warn/Wreturn-type-4.C: Replace -Wreturn-type by + -Wignored-qualifiers. + 2008-01-12 Eric Botcazou <ebotcazou@adacore.com> * gnat.dg/slice3.adb: New test. diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C index dbb089b1812351d48780bfb412fd42b23e8fbfce..20c34a836a9e7821d22333f05f75010a3ce1ec28 100644 --- a/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C +++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-4.C @@ -1,6 +1,6 @@ /* PR c++/18313 */ /* { dg-do compile } */ -/* { dg-options "-Wreturn-type" } */ +/* { dg-options "-Wignored-qualifiers" } */ volatile void bar(); /* { dg-warning "type qualifiers ignored" } */ diff --git a/gcc/testsuite/gcc.dg/qual-return-1.c b/gcc/testsuite/gcc.dg/qual-return-1.c index ac94df6d2bb0787479a504ea0a21bf60eeb81d49..8151995d8b30d81f5668b042ce4a4dd3b6ebd3c4 100644 --- a/gcc/testsuite/gcc.dg/qual-return-1.c +++ b/gcc/testsuite/gcc.dg/qual-return-1.c @@ -1,7 +1,7 @@ /* Test for warnings for qualified function return types. */ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wreturn-type" } */ +/* { dg-options "-std=gnu99 -Wreturn-type -Wignored-qualifiers" } */ /* Qualifying a function return type makes no sense. */