re PR c/30551 (-pedantic does not include -Wmain, but -pedantic-errors does make…

re PR c/30551 (-pedantic does not include -Wmain, but -pedantic-errors does make -Wmain cause error messages)

2008-08-13  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

	PR 30551
	* doc/invoke.texi (Wmain): Update.
	* c-decl.c (start_decl): warn_main is only 0 or 1.
	(start_function): Likewise. Fix formatting.
	(finish_function): Delete redundant warning.
	* c.opt (Wmain): Add Var(warn_main) and Init(-1).
	* c-opts (c_common_handle_option): -Wall only has effect if
	warn_main is uninitialized. OPT_Wmain is automatically
	handled. -pedantic also enables Wmain.
	(c_common_post_options): Handle all logic for Wmain here.
	* c-common.c (warn_main): Delete.
	(check_main_parameter_types): Make pedwarns conditional on
	OPT_Wmain.
	* c-common.h (warn_main): Delete.
cp/	
	* decl.c (grokfndecl): Call check_main_parameters_type only if
	-Wmain.
testsuite/
	* gcc.dg/pr30551.c: New.
	* gcc.dg/pr30551-2.c: New.
	* gcc.dg/pr30551-3.c: New.
	* gcc.dg/pr30551-4.c: New.
	* gcc.dg/pr30551-5.c: New.
	* gcc.dg/pr30551-6.c: New.
	* gcc.dg/tree-ssa/reassoc-3.c: Don't compile with -pedantic-errors.
	* g++.dg/warn/pr30551.C: New.
	* g++.dg/warn/pr30551-2.C: New.

From-SVN: r139063
parent 6cd7942d
2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 30551
* doc/invoke.texi (Wmain): Update.
* c-decl.c (start_decl): warn_main is only 0 or 1.
(start_function): Likewise. Fix formatting.
(finish_function): Delete redundant warning.
* c.opt (Wmain): Add Var(warn_main) and Init(-1).
* c-opts (c_common_handle_option): -Wall only has effect if
warn_main is uninitialized. OPT_Wmain is automatically
handled. -pedantic also enables Wmain.
(c_common_post_options): Handle all logic for Wmain here.
* c-common.c (warn_main): Delete.
(check_main_parameter_types): Make pedwarns conditional on
OPT_Wmain.
* c-common.h (warn_main): Delete.
2008-08-13 H.J. Lu <hongjiu.lu@intel.com> 2008-08-13 H.J. Lu <hongjiu.lu@intel.com>
PR middle-end/36701 PR middle-end/36701
......
...@@ -342,10 +342,6 @@ int flag_isoc99; ...@@ -342,10 +342,6 @@ int flag_isoc99;
int flag_hosted = 1; int flag_hosted = 1;
/* Warn if main is suspicious. */
int warn_main;
/* ObjC language option variables. */ /* ObjC language option variables. */
...@@ -1363,7 +1359,8 @@ check_main_parameter_types (tree decl) ...@@ -1363,7 +1359,8 @@ check_main_parameter_types (tree decl)
{ {
case 1: case 1:
if (TYPE_MAIN_VARIANT (type) != integer_type_node) if (TYPE_MAIN_VARIANT (type) != integer_type_node)
pedwarn (0, "first argument of %q+D should be %<int%>", decl); pedwarn (OPT_Wmain, "first argument of %q+D should be %<int%>",
decl);
break; break;
case 2: case 2:
...@@ -1371,8 +1368,8 @@ check_main_parameter_types (tree decl) ...@@ -1371,8 +1368,8 @@ check_main_parameter_types (tree decl)
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= char_type_node)) != char_type_node))
pedwarn (0, "second argument of %q+D should be %<char **%>", pedwarn (OPT_Wmain, "second argument of %q+D should be %<char **%>",
decl); decl);
break; break;
case 3: case 3:
...@@ -1380,8 +1377,8 @@ check_main_parameter_types (tree decl) ...@@ -1380,8 +1377,8 @@ check_main_parameter_types (tree decl)
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE || TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type))) || (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= char_type_node)) != char_type_node))
pedwarn (0, "third argument of %q+D should probably be " pedwarn (OPT_Wmain, "third argument of %q+D should probably be "
"%<char **%>", decl); "%<char **%>", decl);
break; break;
} }
} }
...@@ -1390,7 +1387,7 @@ check_main_parameter_types (tree decl) ...@@ -1390,7 +1387,7 @@ check_main_parameter_types (tree decl)
argument because it's only mentioned in an appendix of the argument because it's only mentioned in an appendix of the
standard. */ standard. */
if (argct > 0 && (argct < 2 || argct > 3)) if (argct > 0 && (argct < 2 || argct > 3))
pedwarn (0, "%q+D takes only zero or two arguments", decl); pedwarn (OPT_Wmain, "%q+D takes only zero or two arguments", decl);
} }
/* True if pointers to distinct types T1 and T2 can be converted to /* True if pointers to distinct types T1 and T2 can be converted to
......
...@@ -498,11 +498,6 @@ extern int flag_isoc99; ...@@ -498,11 +498,6 @@ extern int flag_isoc99;
extern int flag_hosted; extern int flag_hosted;
/* Warn if main is suspicious. */
extern int warn_main;
/* ObjC language option variables. */ /* ObjC language option variables. */
......
...@@ -3153,8 +3153,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs, ...@@ -3153,8 +3153,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
if (!decl) if (!decl)
return 0; return 0;
if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
&& MAIN_NAME_P (DECL_NAME (decl)))
warning (OPT_Wmain, "%q+D is usually a function", decl); warning (OPT_Wmain, "%q+D is usually a function", decl);
if (initialized) if (initialized)
...@@ -6207,13 +6206,13 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, ...@@ -6207,13 +6206,13 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
maybe_apply_pragma_weak (decl1); maybe_apply_pragma_weak (decl1);
/* Warn for unlikely, improbable, or stupid declarations of `main'. */ /* Warn for unlikely, improbable, or stupid declarations of `main'. */
if (warn_main > 0 && MAIN_NAME_P (DECL_NAME (decl1))) if (warn_main && MAIN_NAME_P (DECL_NAME (decl1)))
{ {
if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1)))
!= integer_type_node) != integer_type_node)
pedwarn (OPT_Wmain, "return type of %q+D is not %<int%>", decl1); pedwarn (OPT_Wmain, "return type of %q+D is not %<int%>", decl1);
check_main_parameter_types(decl1); check_main_parameter_types (decl1);
if (!TREE_PUBLIC (decl1)) if (!TREE_PUBLIC (decl1))
pedwarn (OPT_Wmain, "%q+D is normally a non-static function", decl1); pedwarn (OPT_Wmain, "%q+D is normally a non-static function", decl1);
...@@ -6672,30 +6671,18 @@ finish_function (void) ...@@ -6672,30 +6671,18 @@ finish_function (void)
if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node) if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted) if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
{ && TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl))) == integer_type_node && flag_isoc99)
!= integer_type_node) {
{ tree stmt = c_finish_return (integer_zero_node);
/* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned. /* Hack. We don't want the middle-end to warn that this return
If warn_main is -1 (-Wno-main) we don't want to be warned. */ is unreachable, so we mark its location as special. Using
if (!warn_main) UNKNOWN_LOCATION has the problem that it gets clobbered in
pedwarn (0, "return type of %q+D is not %<int%>", fndecl); annotate_one_with_locus. A cleaner solution might be to
} ensure ! should_carry_locus_p (stmt), but that needs a flag.
else */
{ SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
if (flag_isoc99)
{
tree stmt = c_finish_return (integer_zero_node);
/* Hack. We don't want the middle-end to warn that this return
is unreachable, so we mark its location as special. Using
UNKNOWN_LOCATION has the problem that it gets clobbered in
annotate_one_with_locus. A cleaner solution might be to
ensure ! should_carry_locus_p (stmt), but that needs a flag.
*/
SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
}
}
} }
/* Tie off the statement tree for this function. */ /* Tie off the statement tree for this function. */
......
...@@ -404,9 +404,12 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -404,9 +404,12 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_uninitialized = (value ? 2 : 0); warn_uninitialized = (value ? 2 : 0);
if (!c_dialect_cxx ()) if (!c_dialect_cxx ())
/* We set this to 2 here, but 1 in -Wmain, so -ffreestanding {
can turn it off only if it's not explicit. */ /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding
warn_main = value * 2; can turn it off only if it's not explicit. */
if (warn_main == -1)
warn_main = (value ? 2 : 0);
}
else else
{ {
/* C++-specific warnings. */ /* C++-specific warnings. */
...@@ -467,13 +470,6 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -467,13 +470,6 @@ c_common_handle_option (size_t scode, const char *arg, int value)
cpp_opts->warn_invalid_pch = value; cpp_opts->warn_invalid_pch = value;
break; break;
case OPT_Wmain:
if (value)
warn_main = 1;
else
warn_main = -1;
break;
case OPT_Wmissing_include_dirs: case OPT_Wmissing_include_dirs:
cpp_opts->warn_missing_include_dirs = value; cpp_opts->warn_missing_include_dirs = value;
break; break;
...@@ -615,9 +611,6 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -615,9 +611,6 @@ c_common_handle_option (size_t scode, const char *arg, int value)
case OPT_fhosted: case OPT_fhosted:
flag_hosted = value; flag_hosted = value;
flag_no_builtin = !value; flag_no_builtin = !value;
/* warn_main will be 2 if set by -Wall, 1 if set by -Wmain */
if (!value && warn_main == 2)
warn_main = 0;
break; break;
case OPT_fshort_double: case OPT_fshort_double:
...@@ -907,6 +900,8 @@ c_common_handle_option (size_t scode, const char *arg, int value) ...@@ -907,6 +900,8 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_pointer_sign = 1; warn_pointer_sign = 1;
if (warn_overlength_strings == -1) if (warn_overlength_strings == -1)
warn_overlength_strings = 1; warn_overlength_strings = 1;
if (warn_main == -1)
warn_main = 2;
break; break;
case OPT_print_objc_runtime_info: case OPT_print_objc_runtime_info:
...@@ -1071,6 +1066,15 @@ c_common_post_options (const char **pfilename) ...@@ -1071,6 +1066,15 @@ c_common_post_options (const char **pfilename)
if (warn_overlength_strings == -1 || c_dialect_cxx ()) if (warn_overlength_strings == -1 || c_dialect_cxx ())
warn_overlength_strings = 0; warn_overlength_strings = 0;
/* Wmain is enabled by default in C++ but not in C. */
/* Wmain is disabled by default for -ffreestanding (!flag_hosted),
even if -Wall was given (warn_main will be 2 if set by -Wall, 1
if set by -Wmain). */
if (warn_main == -1)
warn_main = (c_dialect_cxx () && flag_hosted) ? 1 : 0;
else if (warn_main == 2)
warn_main = flag_hosted ? 1 : 0;
/* In C, -Wconversion enables -Wsign-conversion (unless disabled /* In C, -Wconversion enables -Wsign-conversion (unless disabled
through -Wno-sign-conversion). While in C++, through -Wno-sign-conversion). While in C++,
-Wsign-conversion needs to be requested explicitly. */ -Wsign-conversion needs to be requested explicitly. */
......
...@@ -281,7 +281,7 @@ C ObjC C++ ObjC++ Var(warn_long_long) Init(1) Warning ...@@ -281,7 +281,7 @@ C ObjC C++ ObjC++ Var(warn_long_long) Init(1) Warning
Do not warn about using \"long long\" when -pedantic Do not warn about using \"long long\" when -pedantic
Wmain Wmain
C ObjC C++ ObjC++ Warning C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning
Warn about suspicious declarations of \"main\" Warn about suspicious declarations of \"main\"
Wmissing-braces Wmissing-braces
......
2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 30551
* decl.c (grokfndecl): Call check_main_parameters_type only if
-Wmain.
2008-08-12 Paolo Carlini <paolo.carlini@oracle.com> 2008-08-12 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/37087 PR c++/37087
......
...@@ -6692,7 +6692,8 @@ grokfndecl (tree ctype, ...@@ -6692,7 +6692,8 @@ grokfndecl (tree ctype,
newtype = build_function_type (integer_type_node, oldtypeargs); newtype = build_function_type (integer_type_node, oldtypeargs);
TREE_TYPE (decl) = newtype; TREE_TYPE (decl) = newtype;
} }
check_main_parameter_types (decl); if (warn_main)
check_main_parameter_types (decl);
} }
if (ctype != NULL_TREE if (ctype != NULL_TREE
......
...@@ -2940,10 +2940,11 @@ This warning is also enabled by @option{-Wextra}. ...@@ -2940,10 +2940,11 @@ This warning is also enabled by @option{-Wextra}.
@item -Wmain @item -Wmain
@opindex Wmain @opindex Wmain
@opindex Wno-main @opindex Wno-main
Warn if the type of @samp{main} is suspicious. @samp{main} should be a Warn if the type of @samp{main} is suspicious. @samp{main} should be
function with external linkage, returning int, taking either zero a function with external linkage, returning int, taking either zero
arguments, two, or three arguments of appropriate types. arguments, two, or three arguments of appropriate types. This warning
This warning is enabled by @option{-Wall}. is enabled by default in C++ and is enabled by either @option{-Wall}
or @option{-pedantic}.
@item -Wmissing-braces @item -Wmissing-braces
@opindex Wmissing-braces @opindex Wmissing-braces
......
2008-08-13 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 30551
* gcc.dg/pr30551.c: New.
* gcc.dg/pr30551-2.c: New.
* gcc.dg/pr30551-3.c: New.
* gcc.dg/pr30551-4.c: New.
* gcc.dg/pr30551-5.c: New.
* gcc.dg/pr30551-6.c: New.
* gcc.dg/tree-ssa/reassoc-3.c: Don't compile with -pedantic-errors.
* g++.dg/warn/pr30551.C: New.
* g++.dg/warn/pr30551-2.C: New.
2008-08-13 Richard Guenther <rguenther@suse.de> 2008-08-13 Richard Guenther <rguenther@suse.de>
* gcc.dg/tree-ssa/ssa-ccp-21.c: New testcase. * gcc.dg/tree-ssa/ssa-ccp-21.c: New testcase.
......
// PR 30551 -Wmain is enabled by -pedantic/-pedantic-errors.
// { dg-do compile }
// { dg-options "-pedantic-errors" }
int main(char a) {} /* { dg-error "error: first argument of .*main.* should be .int." } */
/* { dg-error "error: .*main.* takes only zero or two arguments" "" { target *-*-* } 5 } */
// PR 30551 -Wmain is enabled by default.
// { dg-do compile }
// { dg-options "" }
int main(char a) {} /* { dg-warning "warning: first argument of .*main.* should be .int." } */
/* { dg-warning "warning: .*main.* takes only zero or two arguments" "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is not enabled by default. */
/* { dg-do compile } */
/* { dg-options "" } */
void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */
/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is enabled by -pedantic-errors. */
/* { dg-do compile } */
/* { dg-options "-pedantic-errors" } */
void main(char a) {} /* { dg-error "first argument of .main. should be .int." } */
/* { dg-error ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-error "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is enabled by -pedantic-errors and can be disabled. */
/* { dg-do compile } */
/* { dg-options "-pedantic-errors -Wno-main" } */
void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */
/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is enabled by -pedantic and can be disabled. */
/* { dg-do compile } */
/* { dg-options "-pedantic -Wno-main" } */
void main(char a) {} /* { dg-bogus "first argument of .main. should be .int." } */
/* { dg-bogus ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-bogus "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is enabled by -pedantic. */
/* { dg-do compile } */
/* { dg-options "-pedantic" } */
void main(char a) {} /* { dg-warning "first argument of .main. should be .int." } */
/* { dg-warning ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-warning "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* PR 30551 -Wmain is enabled by -Wall. */
/* { dg-do compile } */
/* { dg-options "-Wall" } */
void main(char a) {} /* { dg-warning "first argument of .main. should be .int." } */
/* { dg-warning ".main. takes only zero or two arguments" "" { target *-*-* } 5 } */
/* { dg-warning "return type of .main. is not .int." "" { target *-*-* } 5 } */
/* { dg-options "" } */
int main(int a, int b, int c, int d) int main(int a, int b, int c, int d)
{ {
int e = (a & ~b) & (~c & d); int e = (a & ~b) & (~c & d);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment