Hi,

While compiling a certain unnamed piece of mail server software, that is
a sort of mix of C99-like constructs and an extremely old K&R core, I
repeatedly received the following type of warning:

  int foo(char x, int y);

  int foo(x, y)
  char x;
  int y;
  {
    return x * y;
  }

  // $ clang -c knrpromo.c
  // knrpromo.c:4:6: warning: promoted type 'int' of K&R function parameter is 
not compatible with the parameter type 'char' declared in a previous prototype
  // char x;
  //      ^
  // knrpromo.c:1:14: note: previous declaration is here
  // int foo(char x, int y);
  //              ^
  // 1 warning generated.

Apparently, this is because of the promotion rules for K&R function
parameters, which are always converted to int.

While this warning is fine in itself, it cannot be turned off, which is
a nuisance, as it would be very disruptive to edit all the dozens, if
not hundreds, of prototypes and definitions in the program to fix these
cases.

Therefore, I propose the attached patch, which adds a new warning option
(-Wknr-promoted-parameter) for turning it on or off.  This runs through
the standard tests just fine.
Index: tools/clang/test/Misc/warning-flags.c
===================================================================
--- tools/clang/test/Misc/warning-flags.c	(revision 146850)
+++ tools/clang/test/Misc/warning-flags.c	(working copy)
@@ -56,7 +56,6 @@ CHECK-NEXT:   ext_missing_whitespace_after_macro_n
 CHECK-NEXT:   ext_new_paren_array_nonconst
 CHECK-NEXT:   ext_nonstandard_escape
 CHECK-NEXT:   ext_param_not_declared
-CHECK-NEXT:   ext_param_promoted_not_compatible_with_prototype
 CHECK-NEXT:   ext_paste_comma
 CHECK-NEXT:   ext_plain_complex
 CHECK-NEXT:   ext_pp_bad_vaargs_use
Index: tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	(revision 146850)
+++ tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -1825,7 +1825,8 @@ def note_default_argument_declared_here : Note<
 
 def ext_param_promoted_not_compatible_with_prototype : ExtWarn<
   "promoted type %0 of K&R function parameter is not compatible with the "
-  "parameter type %1 declared in a previous prototype">;
+  "parameter type %1 declared in a previous prototype">,
+  InGroup<KNRPromotedParameter>;
 
 
 // C++ Overloading Semantic Analysis.
Index: tools/clang/include/clang/Basic/DiagnosticGroups.td
===================================================================
--- tools/clang/include/clang/Basic/DiagnosticGroups.td	(revision 146850)
+++ tools/clang/include/clang/Basic/DiagnosticGroups.td	(working copy)
@@ -88,6 +88,7 @@ def LogicalOpParentheses: DiagGroup<"logical-op-pa
 def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">;
 def : DiagGroup<"import">;
 def IncompatiblePointerTypes : DiagGroup<"incompatible-pointer-types">;
+def KNRPromotedParameter : DiagGroup<"knr-promoted-parameter">;
 def : DiagGroup<"init-self">;
 def : DiagGroup<"inline">;
 def : DiagGroup<"int-to-pointer-cast">;
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to