* [C PATCH] Make -Wno-implicit-int work in C99 mode
@ 2014-10-17 11:51 Marek Polacek
2014-10-17 16:28 ` Joseph S. Myers
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2014-10-17 11:51 UTC (permalink / raw)
To: GCC Patches, Joseph S. Myers
C99 mode warns about defaulting to int by default, but without
the possibility to suppress the warning with -Wno-implicit-int.
This is likely to arouse the ire of the users, especially with
the new default.
Therefore the following patch tweaks warn_implicit_int in such
a way that -Wimplicit and -Wimplicit-int should work as intended
(following the rule that more specific option takes precedence
over the less specific). There should be no changes in GNU89
mode.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2014-10-17 Marek Polacek <polacek@redhat.com>
c-family/
* c-opts.c (c_common_post_options): Set warn_implicit_int.
* c.opt (Wimplicit-int): Initialize to -1.
c/
* c-decl.c (grokdeclarator): Use OPT_Wimplicit_int unconditionally.
(start_function): Use OPT_Wimplicit_int instead of 0.
(store_parm_decls_oldstyle): Likewise.
testsuite/
* gcc.dg/Wimplicit-int-1.c: New test.
* gcc.dg/Wimplicit-int-2.c: New test.
* gcc.dg/Wimplicit-int-3.c: New test.
* gcc.dg/Wimplicit-int-4.c: New test.
diff --git gcc/c-family/c-opts.c gcc/c-family/c-opts.c
index eb078e3..448eb3e 100644
--- gcc/c-family/c-opts.c
+++ gcc/c-family/c-opts.c
@@ -864,6 +864,10 @@ c_common_post_options (const char **pfilename)
if (warn_implicit_function_declaration == -1)
warn_implicit_function_declaration = flag_isoc99;
+ /* -Wimplicit-int is enabled by default for C99. */
+ if (warn_implicit_int == -1)
+ warn_implicit_int = flag_isoc99;
+
/* Declone C++ 'structors if -Os. */
if (flag_declone_ctor_dtor == -1)
flag_declone_ctor_dtor = optimize_size;
diff --git gcc/c-family/c.opt gcc/c-family/c.opt
index 72ac2ed..4f96cf8 100644
--- gcc/c-family/c.opt
+++ gcc/c-family/c.opt
@@ -488,7 +488,7 @@ C ObjC Var(warn_implicit_function_declaration) Init(-1) Warning LangEnabledBy(C
Warn about implicit function declarations
Wimplicit-int
-C ObjC Var(warn_implicit_int) Warning LangEnabledBy(C ObjC,Wimplicit)
+C ObjC Var(warn_implicit_int) Init(-1) Warning LangEnabledBy(C ObjC,Wimplicit)
Warn when a declaration does not specify a type
Wimport
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 839c67b..b18da48 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -5330,11 +5330,11 @@ grokdeclarator (const struct c_declarator *declarator,
else
{
if (name)
- warn_defaults_to (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int,
+ warn_defaults_to (loc, OPT_Wimplicit_int,
"type defaults to %<int%> in declaration "
"of %qE", name);
else
- warn_defaults_to (loc, flag_isoc99 ? 0 : OPT_Wimplicit_int,
+ warn_defaults_to (loc, OPT_Wimplicit_int,
"type defaults to %<int%> in type name");
}
}
@@ -8120,7 +8120,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
}
if (warn_about_return_type)
- warn_defaults_to (loc, flag_isoc99 ? 0
+ warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int
: (warn_return_type ? OPT_Wreturn_type
: OPT_Wimplicit_int),
"return type defaults to %<int%>");
@@ -8429,7 +8429,8 @@ store_parm_decls_oldstyle (tree fndecl, const struct c_arg_info *arg_info)
if (flag_isoc99)
pedwarn (DECL_SOURCE_LOCATION (decl),
- 0, "type of %qD defaults to %<int%>", decl);
+ OPT_Wimplicit_int, "type of %qD defaults to %<int%>",
+ decl);
else
warning_at (DECL_SOURCE_LOCATION (decl),
OPT_Wmissing_parameter_type,
diff --git gcc/testsuite/gcc.dg/Wimplicit-int-1.c gcc/testsuite/gcc.dg/Wimplicit-int-1.c
index e69de29..0c89caf 100644
--- gcc/testsuite/gcc.dg/Wimplicit-int-1.c
+++ gcc/testsuite/gcc.dg/Wimplicit-int-1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+static l; /* { dg-warning "type defaults to" } */
+
+foo (a) /* { dg-warning "return type defaults to" } */
+/* { dg-warning "type of .a. defaults to .int." "type" { target *-*-* } 6 } */
+{
+ auto p; /* { dg-warning "type defaults to" } */
+ typedef bar; /* { dg-warning "type defaults to" } */
+}
diff --git gcc/testsuite/gcc.dg/Wimplicit-int-2.c gcc/testsuite/gcc.dg/Wimplicit-int-2.c
index e69de29..158b61c 100644
--- gcc/testsuite/gcc.dg/Wimplicit-int-2.c
+++ gcc/testsuite/gcc.dg/Wimplicit-int-2.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+static l; /* { dg-error "type defaults to" } */
+
+foo (a) /* { dg-error "return type defaults to" } */
+/* { dg-error "type of .a. defaults to .int." "type" { target *-*-* } 6 } */
+{
+ auto p; /* { dg-error "type defaults to" } */
+ typedef bar; /* { dg-error "type defaults to" } */
+}
diff --git gcc/testsuite/gcc.dg/Wimplicit-int-3.c gcc/testsuite/gcc.dg/Wimplicit-int-3.c
index e69de29..654ce73 100644
--- gcc/testsuite/gcc.dg/Wimplicit-int-3.c
+++ gcc/testsuite/gcc.dg/Wimplicit-int-3.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors -Wno-implicit-int" } */
+
+static l;
+
+foo (a)
+{
+ auto p;
+ typedef bar;
+}
diff --git gcc/testsuite/gcc.dg/Wimplicit-int-4.c gcc/testsuite/gcc.dg/Wimplicit-int-4.c
index e69de29..b2528356 100644
--- gcc/testsuite/gcc.dg/Wimplicit-int-4.c
+++ gcc/testsuite/gcc.dg/Wimplicit-int-4.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Wno-implicit -Wimplicit-int" } */
+
+static l; /* { dg-warning "type defaults to" } */
+
+foo (a) /* { dg-warning "return type defaults to" } */
+/* { dg-warning "type of .a. defaults to .int." "type" { target *-*-* } 6 } */
+{
+ auto p; /* { dg-warning "type defaults to" } */
+ typedef bar; /* { dg-warning "type defaults to" } */
+}
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [C PATCH] Make -Wno-implicit-int work in C99 mode
2014-10-17 11:51 [C PATCH] Make -Wno-implicit-int work in C99 mode Marek Polacek
@ 2014-10-17 16:28 ` Joseph S. Myers
0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2014-10-17 16:28 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Fri, 17 Oct 2014, Marek Polacek wrote:
> C99 mode warns about defaulting to int by default, but without
> the possibility to suppress the warning with -Wno-implicit-int.
> This is likely to arouse the ire of the users, especially with
> the new default.
>
> Therefore the following patch tweaks warn_implicit_int in such
> a way that -Wimplicit and -Wimplicit-int should work as intended
> (following the rule that more specific option takes precedence
> over the less specific). There should be no changes in GNU89
> mode.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-17 16:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-17 11:51 [C PATCH] Make -Wno-implicit-int work in C99 mode Marek Polacek
2014-10-17 16:28 ` Joseph S. Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).