Hi,

a mail in the gcc-list https://gcc.gnu.org/ml/gcc/2018-01/msg00144.html
reminded me about this minor stuff I have (so it can be controlled by -Werror),
but never managed to write testcases. I'm posting it here in case
it's good enough or someone wants to take over from here.

Franz


c/ChangeLog;
2018-01-22  Franz Sirl  <franz.sirl-ker...@lauterbach.com>

    * c-decl.c (grokdeclarator): Use OPT_Wextern_initializer.
    * c-typeck.c (build_binary_op): Use
    OPT_Wcompare_distinct_pointer_types.


c-family/ChangeLog:
2018-01-22  Franz Sirl  <franz.sirl-ker...@lauterbach.com>

    * c.opt (-Wcompare-distinct-pointer-types): New option.
    (-Wextern-initializer): Likewise.


cp/ChangeLog:
2018-01-22  Franz Sirl  <franz.sirl-ker...@lauterbach.com>

    * decl.c (grokdeclarator): Use OPT_Wextern_initializer.
    * typeck.c (composite_pointer_error): Use
    OPT_Wcompare_distinct_pointer_types.


Index: gcc-trunk/gcc/c-family/c.opt
===================================================================
--- gcc-trunk/gcc/c-family/c.opt        (revision 256939)
+++ gcc-trunk/gcc/c-family/c.opt        (working copy)
@@ -318,10 +318,6 @@
 alloca, and on bounded uses of alloca whose bound can be larger than
 <number> bytes.
 
-Warray-bounds
-LangEnabledBy(C ObjC C++ ObjC++,Wall)
-; in common.opt
-
 Warray-bounds=
 LangEnabledBy(C ObjC C++ ObjC++,Wall,1,0)
 ; in common.opt
@@ -420,6 +416,10 @@
 C ObjC C++ ObjC++ Warning Alias(Wcomment)
 Synonym for -Wcomment.
 
+Wcompare-distinct-pointer-types
+C ObjC C++ ObjC++ Var(warn_distinct_pointer_types) Init(1) Warning
+Warn for comparison of distinct pointer types.
+
 Wconditionally-supported
 C++ ObjC++ Var(warn_conditionally_supported) Warning
 Warn for conditionally-supported constructs.
@@ -512,6 +512,10 @@
 C ObjC RejectNegative Warning Alias(Werror=, implicit-function-declaration)
 This switch is deprecated; use -Werror=implicit-function-declaration instead.
 
+Wextern-initializer
+C ObjC C++ ObjC++ Var(warn_extern_initializer) Init(1) Warning
+Warn about extern declarations with an initializer.
+
 Wextra
 C ObjC C++ ObjC++ Warning
 ; in common.opt
@@ -694,6 +698,10 @@
 C C++ Common Var(warn_misleading_indentation) Warning LangEnabledBy(C C++,Wall)
 Warn when the indentation of the code does not reflect the block structure.
 
+Wmisleading-indentation-ltb
+C C++ Common Var(warn_misleading_indentation_ltb) Warning
+Warn when the indentation of the code does not reflect the block structure.
+
 Wmissing-braces
 C ObjC C++ ObjC++ Var(warn_missing_braces) Warning LangEnabledBy(C ObjC,Wall)
 Warn about possibly missing braces around initializers.
Index: gcc-trunk/gcc/c/c-decl.c
===================================================================
--- gcc-trunk/gcc/c/c-decl.c    (revision 256939)
+++ gcc-trunk/gcc/c/c-decl.c    (working copy)
@@ -5888,8 +5888,8 @@
            /* It is fine to have 'extern const' when compiling at C
               and C++ intersection.  */
            if (!(warn_cxx_compat && constp))
-             warning_at (loc, 0, "%qE initialized and declared %<extern%>",
-                        name);
+             warning_at (loc, OPT_Wextern_initializer,
+                        "%qE initialized and declared %<extern%>", name);
          }
       else
        error_at (loc, "%qE has both %<extern%> and initializer", name);
Index: gcc-trunk/gcc/cp/decl.c
===================================================================
--- gcc-trunk/gcc/cp/decl.c     (revision 256939)
+++ gcc-trunk/gcc/cp/decl.c     (working copy)
@@ -12408,7 +12408,8 @@
            /* It's common practice (and completely valid) to have a const
               be initialized and declared extern.  */
            if (!(type_quals & TYPE_QUAL_CONST))
-             warning (0, "%qs initialized and declared %<extern%>", name);
+             warning_at (input_location, OPT_Wextern_initializer,
+                         "%qs initialized and declared %<extern%>", name);
          }
        else
          {
Index: gcc-trunk/gcc/c/c-typeck.c
===================================================================
--- gcc-trunk/gcc/c/c-typeck.c  (revision 256939)
+++ gcc-trunk/gcc/c/c-typeck.c  (working copy)
@@ -11599,8 +11599,9 @@
          else
            /* Avoid warning about the volatile ObjC EH puts on decls.  */
            if (!objc_ok)
-             pedwarn (location, 0,
-                      "comparison of distinct pointer types lacks a cast");
+             pedwarn (location, OPT_Wcompare_distinct_pointer_types,
+                      "comparison of distinct pointer types "
+                      "%qT and %qT lacks a cast", type0, type1);
 
          if (result_type == NULL_TREE)
            {
@@ -11711,8 +11712,9 @@
              int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
              result_type = build_pointer_type
                              (build_qualified_type (void_type_node, qual));
-             pedwarn (location, 0,
-                      "comparison of distinct pointer types lacks a cast");
+             pedwarn (location, OPT_Wcompare_distinct_pointer_types,
+                      "comparison of distinct pointer types "
+                      "%qT and %qT lacks a cast", type0, type1);
            }
        }
       else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
Index: gcc-trunk/gcc/cp/typeck.c
===================================================================
--- gcc-trunk/gcc/cp/typeck.c   (revision 256939)
+++ gcc-trunk/gcc/cp/typeck.c   (working copy)
@@ -453,7 +453,8 @@
   switch (operation)
     {
     case CPO_COMPARISON:
-      emit_diagnostic (kind, input_location, 0,
+      emit_diagnostic (kind, input_location,
+                      OPT_Wcompare_distinct_pointer_types,
                       "comparison between "
                       "distinct pointer types %qT and %qT lacks a cast",
                       t1, t2);

Reply via email to