Bug 40989 - -Werror= and #pragma diagnostics do not work with group flags
Summary: -Werror= and #pragma diagnostics do not work with group flags
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on: 53063
Blocks:
  Show dependency treegraph
 
Reported: 2009-08-06 15:06 UTC by Diego Elio Pettenò
Modified: 2019-05-21 13:50 UTC (History)
2 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-08-07 13:07:11


Attachments
patch (3.83 KB, patch)
2010-03-12 00:15 UTC, Manuel López-Ibáñez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Diego Elio Pettenò 2009-08-06 15:06:30 UTC
I'm not sure if this is the cause of the final bug I'm trying to reproduce out of a project of mine (implicit function declarations are not reported having any value to the side with -fdiagnostics-show-option), but anyway…

While the man page for gcc implies that -Werror=foo enables -Wfoo, this doesn't seem to be the case:

flame@yamato mytmpfs % cat test.c
int main() {
  return pippo();
}
flame@yamato mytmpfs % gcc -c -Werror=implicit -fdiagnostics-show-option test.c -o test.o
flame@yamato mytmpfs % gcc -c -Wimplicit -fdiagnostics-show-option test.c -o test.o         
test.c: In function ‘main’:
test.c:2: warning: implicit declaration of function ‘pippo’ [-Wimplicit-function-declaration]

Doesn't look right to me.
Comment 1 Diego Elio Pettenò 2009-08-06 15:10:15 UTC
I can confirm this issue on 4.3.3 as well.
Comment 2 Manuel López-Ibáñez 2009-08-07 13:07:11 UTC
This is because neither Werror= nor #pragma GCC diagnositcs work with "group flags", that is, flags that enable other flags. 

Until this is fixed, you need to give exactly the flag reported by -fdiagnostics-show-option, so in your case it would be:

-Werror=implicit-function-declaration

if none is reported that is also a bug, so open another PR.

Comment 3 Manuel López-Ibáñez 2010-03-12 00:15:37 UTC
Created attachment 20091 [details]
patch

This is my current patch to fix this. However, it has a big problem: Since there is no "namespace" for options (all options are visible from everywhere), functions referenced in options.h must be defined in a file that is linked with everything, which is very inconvenient. Any ideas how to overcome this?
Comment 4 Manuel López-Ibáñez 2010-05-06 10:12:52 UTC
Subject: Bug 40989

Author: manu
Date: Thu May  6 10:12:36 2010
New Revision: 159102

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159102
Log:
2010-05-06  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR 40989
	* doc/invoke.texi (Wimplicit): Document as C only.
	* opts.c (common_handle_option): Add argument kind.
	(handle_option): Rename as read_cmdline_option. Factor out code to...
	(handle_option): ... here. New.
	(handle_options): Rename as read_cmdline_options.
	(decode_options): Update call.
	(set_option): Use option index instead of option pointer. Classify
	diagnostics correctly.
	(enable_warning_as_error): Call handle_option.
	* opts.h (set_option): Update declaration.
	(handle_option): Declare.
	* langhooks.h (struct lang_hooks): Add argument kind to
	handle_option.
	* c.opt (Wimplicit,Wimplicit-int): Initialize to -1.
	* c-opts.c (set_Wimplicit): Delete.
	(c_family_lang_mask): New static constant.
	(c_common_handle_option): Add argument kind. Use handle_option
	instead of set_Wimplicit.
	(c_common_post_options): warn_implicit and warn_implicit_int
	are disabled by default.
	* c-common.c (warn_implicit): Do not define here.
	* c-common.h (warn_implicit): Do not declare here.
	(c_common_handle_option): Update declaration.
	* lto-opts.c (lto_reissue_options): Update call to set_option.
java/
	* lang.c (java_handle_option): Add argument kind.
fortran/	
	* options.c (gfc_handle_option): Add argument kind.
	* gfortran.h (gfc_handle_option): Update declaration.
ada/
	* gcc-interface/misc.c (gnat_handle_option): Add argument kind.
testsuite/
	* gcc.dg/pr40989.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/pr40989.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/gcc-interface/misc.c
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-opts.c
    trunk/gcc/c.opt
    trunk/gcc/doc/invoke.texi
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/options.c
    trunk/gcc/java/ChangeLog
    trunk/gcc/java/lang.c
    trunk/gcc/langhooks.h
    trunk/gcc/lto-opts.c
    trunk/gcc/opts.c
    trunk/gcc/opts.h
    trunk/gcc/testsuite/ChangeLog

Comment 5 Manuel López-Ibáñez 2010-05-06 10:22:41 UTC
OK, this is fixed for -Wimplicit and the infrastructure is there to fix it for all other group flags (just use the new handle_option to enable sub-flags). However, I don't have time at the moment to go over all subflags. So anyone, feel free to submit patches about this. If you need some help or mentoring, just ask.
Comment 6 Eric Botcazou 2010-05-07 10:26:20 UTC
Subject: Bug 40989

Author: ebotcazou
Date: Fri May  7 10:25:54 2010
New Revision: 159149

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159149
Log:
	PR 40989
	* gcc-interface/misc.c (gnat_handle_option): Fix long line.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/gcc-interface/misc.c

Comment 7 Manuel López-Ibáñez 2012-04-28 00:11:12 UTC
Doing this option by option is stupid. Groups options should be encoded in .opt files and the code to handle sub-options be automatically generated. PR50363 needs to be fixed first.
Comment 8 Manuel López-Ibáñez 2012-10-16 15:31:55 UTC
Author: manu
Date: Tue Oct 16 15:31:46 2012
New Revision: 192502

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192502
Log:
2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/53063
	PR c/40989
gcc/
	* optc-gen.awk: Handle new form of LangEnabledBy.
	* opts.c (set_Wstrict_aliasing): Declare here. Make static.
	* common.opt (Wstrict-aliasing=,Wstrict-overflow=): Do not use Init.
	* doc/options.texi (LangEnabledBy): Document new form.
	* flags.h (set_Wstrict_aliasing): Do not declare.
c-family/
	* c.opt (Wstrict-aliasing=,Wstrict-overflow=): Use LangEnabledBy.
	* c-opts.c (c_common_handle_option): Do not set them here. Add
	comment.
	(c_common_post_options): Likewise.
testsuite/
	* gcc.dg/Wstrict-overflow-24.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/Wstrict-overflow-24.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-opts.c
    trunk/gcc/c-family/c.opt
    trunk/gcc/common.opt
    trunk/gcc/doc/options.texi
    trunk/gcc/flags.h
    trunk/gcc/optc-gen.awk
    trunk/gcc/opts.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Manuel López-Ibáñez 2012-10-16 15:39:08 UTC
Author: manu
Date: Tue Oct 16 15:38:58 2012
New Revision: 192503

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192503
Log:
2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/53063
	PR c/40989
	* doc/options.texi (EnabledBy): Document new form.
	* optc-gen.awk: Handle new form of EnabledBy.
	* common.opt (Wunused-but-set-parameter): Use EnabledBy.
	(Wunused-parameter): Likewise.
	* opts.c (finish_options): Do not handle them explicitly.
	* opt-functions.awk (search_var_name): New.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/common.opt
    trunk/gcc/doc/options.texi
    trunk/gcc/opt-functions.awk
    trunk/gcc/optc-gen.awk
    trunk/gcc/opts.c
Comment 10 Manuel López-Ibáñez 2012-10-20 14:17:14 UTC
Author: manu
Date: Sat Oct 20 14:17:08 2012
New Revision: 192635

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192635
Log:
2012-10-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>

	PR c/53063
	PR c/40989
c-family/
	* c.opt (Waddress,Wchar-subscripts,Wsign-conversion,Wimplicit,
	Wimplicit-function-declaration,Wimplicit-int,Wsizeof-pointer-memaccess,
	Wnarrowing,Wparentheses,Wpointer-sign,Wreturn-type,Wsequence-point,
	Wsign-compare,Wuninitialized,Wmaybe-uninitialized,Wunused,
	Wvolatile-register-var): Add LangEnabledBy or EnabledBy.
	* c-opts.c (c_common_handle_option): Remove explicit handling from
	here.
	(c_common_post_options): Likewise.
gcc/
	* opts.c (finish_options): Remove explicit handling from here.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-opts.c
    trunk/gcc/c-family/c.opt
    trunk/gcc/opts.c
Comment 11 Manuel López-Ibáñez 2014-08-19 09:37:12 UTC
I consider this FIXED. Almost all options now work. The ones that don't are due to missing features in the *.opt files, which are tracked in PR53063.