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>
PR middle-end/36701
......
......@@ -342,10 +342,6 @@ int flag_isoc99;
int flag_hosted = 1;
/* Warn if main is suspicious. */
int warn_main;
/* ObjC language option variables. */
......@@ -1363,7 +1359,8 @@ check_main_parameter_types (tree decl)
{
case 1:
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;
case 2:
......@@ -1371,7 +1368,7 @@ check_main_parameter_types (tree decl)
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= 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);
break;
......@@ -1380,7 +1377,7 @@ check_main_parameter_types (tree decl)
|| TREE_CODE (TREE_TYPE (type)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (type)))
!= 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);
break;
}
......@@ -1390,7 +1387,7 @@ check_main_parameter_types (tree decl)
argument because it's only mentioned in an appendix of the
standard. */
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
......
......@@ -498,11 +498,6 @@ extern int flag_isoc99;
extern int flag_hosted;
/* Warn if main is suspicious. */
extern int warn_main;
/* ObjC language option variables. */
......
......@@ -3153,8 +3153,7 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
if (!decl)
return 0;
if (warn_main > 0 && TREE_CODE (decl) != FUNCTION_DECL
&& MAIN_NAME_P (DECL_NAME (decl)))
if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
warning (OPT_Wmain, "%q+D is usually a function", decl);
if (initialized)
......@@ -6207,13 +6206,13 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator,
maybe_apply_pragma_weak (decl1);
/* 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)))
!= integer_type_node)
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))
pedwarn (OPT_Wmain, "%q+D is normally a non-static function", decl1);
......@@ -6672,19 +6671,9 @@ finish_function (void)
if (DECL_RESULT (fndecl) && DECL_RESULT (fndecl) != error_mark_node)
DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted)
{
if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
!= integer_type_node)
{
/* If warn_main is 1 (-Wmain) or 2 (-Wall), we have already warned.
If warn_main is -1 (-Wno-main) we don't want to be warned. */
if (!warn_main)
pedwarn (0, "return type of %q+D is not %<int%>", fndecl);
}
else
{
if (flag_isoc99)
if (MAIN_NAME_P (DECL_NAME (fndecl)) && flag_hosted
&& TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (fndecl)))
== integer_type_node && flag_isoc99)
{
tree stmt = c_finish_return (integer_zero_node);
/* Hack. We don't want the middle-end to warn that this return
......@@ -6695,8 +6684,6 @@ finish_function (void)
*/
SET_EXPR_LOCATION (stmt, BUILTINS_LOCATION);
}
}
}
/* Tie off the statement tree for this function. */
DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
......
......@@ -404,9 +404,12 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_uninitialized = (value ? 2 : 0);
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. */
warn_main = value * 2;
if (warn_main == -1)
warn_main = (value ? 2 : 0);
}
else
{
/* C++-specific warnings. */
......@@ -467,13 +470,6 @@ c_common_handle_option (size_t scode, const char *arg, int value)
cpp_opts->warn_invalid_pch = value;
break;
case OPT_Wmain:
if (value)
warn_main = 1;
else
warn_main = -1;
break;
case OPT_Wmissing_include_dirs:
cpp_opts->warn_missing_include_dirs = value;
break;
......@@ -615,9 +611,6 @@ c_common_handle_option (size_t scode, const char *arg, int value)
case OPT_fhosted:
flag_hosted = 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;
case OPT_fshort_double:
......@@ -907,6 +900,8 @@ c_common_handle_option (size_t scode, const char *arg, int value)
warn_pointer_sign = 1;
if (warn_overlength_strings == -1)
warn_overlength_strings = 1;
if (warn_main == -1)
warn_main = 2;
break;
case OPT_print_objc_runtime_info:
......@@ -1071,6 +1066,15 @@ c_common_post_options (const char **pfilename)
if (warn_overlength_strings == -1 || c_dialect_cxx ())
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
through -Wno-sign-conversion). While in C++,
-Wsign-conversion needs to be requested explicitly. */
......
......@@ -281,7 +281,7 @@ C ObjC C++ ObjC++ Var(warn_long_long) Init(1) Warning
Do not warn about using \"long long\" when -pedantic
Wmain
C ObjC C++ ObjC++ Warning
C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning
Warn about suspicious declarations of \"main\"
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>
PR c++/37087
......
......@@ -6692,6 +6692,7 @@ grokfndecl (tree ctype,
newtype = build_function_type (integer_type_node, oldtypeargs);
TREE_TYPE (decl) = newtype;
}
if (warn_main)
check_main_parameter_types (decl);
}
......
......@@ -2940,10 +2940,11 @@ This warning is also enabled by @option{-Wextra}.
@item -Wmain
@opindex Wmain
@opindex Wno-main
Warn if the type of @samp{main} is suspicious. @samp{main} should be a
function with external linkage, returning int, taking either zero
arguments, two, or three arguments of appropriate types.
This warning is enabled by @option{-Wall}.
Warn if the type of @samp{main} is suspicious. @samp{main} should be
a function with external linkage, returning int, taking either zero
arguments, two, or three arguments of appropriate types. This warning
is enabled by default in C++ and is enabled by either @option{-Wall}
or @option{-pedantic}.
@item -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>
* 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 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