]> gcc.gnu.org Git - gcc.git/commitdiff
re PR c/43245 (add option to control "discarding qualifiers" warnings)
authorMarek Polacek <polacek@redhat.com>
Thu, 1 May 2014 07:16:10 +0000 (07:16 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 1 May 2014 07:16:10 +0000 (07:16 +0000)
PR c/43245
* doc/invoke.texi: Document -Wdiscarded-qualifiers.
c-family/
* c.opt (Wdiscarded-qualifiers): Add.
c/
* c-typeck.c (convert_for_assignment): Pass OPT_Wdiscarded_qualifiers
instead of 0 to WARN_FOR_QUALIFIERS.
testsuite/
* gcc.dg/pr43245.c: New test.

From-SVN: r209970

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c.opt
gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr43245.c [new file with mode: 0644]

index e3ae8dcfc81eec33e33c32a52d5d0f740f6267c3..2d2b7878c4c7856585a68648de12a98c56773956 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43245
+       * doc/invoke.texi: Document -Wdiscarded-qualifiers.
+
 2014-04-30  Alan Lawrence  <alan.lawrence@arm.com>
 
        * config/aarch64/arm_neon.h (vuzp1_f32, vuzp1_p8, vuzp1_p16, vuzp1_s8,
index 47bb11438ad997dbca72276e6f48c23b0e0b502c..fddfcd8c2f04af69010c38dedb3e68b2bf9fb155 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43245
+       * c.opt (Wdiscarded-qualifiers): Add.
+
 2014-04-30  Marek Polacek  <polacek@redhat.com>
 
        * c-ubsan.c (ubsan_instrument_division): Handle REAL_TYPEs.  Perform
index 94447082fb54173b83269259d3473281771d1023..1bbb81c8425b3bde4b0f617a55bce0d2c4cb839a 100644 (file)
@@ -355,6 +355,10 @@ Wdeprecated
 C C++ ObjC ObjC++ Var(warn_deprecated) Init(1) Warning
 Warn if a deprecated compiler feature, class, method, or field is used
 
+Wdiscarded-qualifiers
+C ObjC Var(warn_discarded_qualifiers) Init(1) Warning
+Warn if type qualifiers on pointers are discarded
+
 Wdiv-by-zero
 C ObjC C++ ObjC++ Var(warn_div_by_zero) Init(1) Warning
 Warn about compile-time integer division by zero
index cee032969b622253aceb0332c957bd5fa2021acc..b10f6f7da9f873242e4d1dc0144334e036f5155d 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43245
+       * c-typeck.c (convert_for_assignment): Pass OPT_Wdiscarded_qualifiers
+       instead of 0 to WARN_FOR_QUALIFIERS.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/56989
index 409b0a7b99cbeef4e6305aaadb8c9d1ef1c45d66..e25a25ca48e823a952cfbbf67c07b48083d75d87 100644 (file)
@@ -5852,7 +5852,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
                     vice-versa.  */
                  if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
                      & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
-                   WARN_FOR_QUALIFIERS (location, 0,
+                   WARN_FOR_QUALIFIERS (location, OPT_Wdiscarded_qualifiers,
                                         G_("passing argument %d of %qE "
                                            "makes %q#v qualified function "
                                            "pointer from unqualified"),
@@ -5868,7 +5868,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
                }
              else if (TYPE_QUALS_NO_ADDR_SPACE (ttr)
                       & ~TYPE_QUALS_NO_ADDR_SPACE (ttl))
-               WARN_FOR_QUALIFIERS (location, 0,
+               WARN_FOR_QUALIFIERS (location, OPT_Wdiscarded_qualifiers,
                                     G_("passing argument %d of %qE discards "
                                        "%qv qualifier from pointer target type"),
                                     G_("assignment discards %qv qualifier "
@@ -6049,7 +6049,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
              if (TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttr)
                  & ~TYPE_QUALS_NO_ADDR_SPACE_NO_ATOMIC (ttl))
                {
-                 WARN_FOR_QUALIFIERS (location, 0,
+                 WARN_FOR_QUALIFIERS (location, OPT_Wdiscarded_qualifiers,
                                       G_("passing argument %d of %qE discards "
                                          "%qv qualifier from pointer target type"),
                                       G_("assignment discards %qv qualifier "
@@ -6086,7 +6086,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
                 where an ordinary one is wanted, but not vice-versa.  */
              if (TYPE_QUALS_NO_ADDR_SPACE (ttl)
                  & ~TYPE_QUALS_NO_ADDR_SPACE (ttr))
-               WARN_FOR_QUALIFIERS (location, 0,
+               WARN_FOR_QUALIFIERS (location, OPT_Wdiscarded_qualifiers,
                                     G_("passing argument %d of %qE makes "
                                        "%q#v qualified function pointer "
                                        "from unqualified"),
index cc6d405f1685b4e16c312bdd2613394309b94339..0eba1e0a162caf9abd8372300ad700d614bb2c39 100644 (file)
@@ -242,6 +242,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wchar-subscripts -Wclobbered  -Wcomment -Wconditionally-supported  @gol
 -Wconversion -Wcoverage-mismatch -Wdate-time -Wdelete-incomplete -Wno-cpp  @gol
 -Wno-deprecated -Wno-deprecated-declarations -Wdisabled-optimization  @gol
+-Wno-discarded-qualifiers @gol
 -Wno-div-by-zero -Wdouble-promotion -Wempty-body  -Wenum-compare @gol
 -Wno-endif-labels -Werror  -Werror=* @gol
 -Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
@@ -4182,6 +4183,15 @@ This option is only active when @option{-ftree-vrp} is active
 (default for @option{-O2} and above). It warns about subscripts to arrays
 that are always out of bounds. This warning is enabled by @option{-Wall}.
 
+@item -Wno-discarded-qualifiers
+@opindex Wno-discarded-qualifiers
+@opindex Wdiscarded-qualifiers
+Do not warn if type qualifiers on pointers are being discarded.
+Typically, the compiler will warn if a @code{const char *} variable is
+passed to a function that takes @code{char *} parameter.  This option
+can be used to suppress such a warning.  This warning is only supported
+for C.
+
 @item -Wno-div-by-zero
 @opindex Wno-div-by-zero
 @opindex Wdiv-by-zero
index c62126e98dc3bd119155ac6a8c6221d6436271aa..619049730bd947097263dd0b5481feb310203a1a 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43245
+       * gcc.dg/pr43245.c: New test.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/56989
diff --git a/gcc/testsuite/gcc.dg/pr43245.c b/gcc/testsuite/gcc.dg/pr43245.c
new file mode 100644 (file)
index 0000000..85490ff
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR c/43245 */
+/* { dg-do compile } */
+/* { dg-options "-Wno-discarded-qualifiers" } */
+
+void
+foo (char *p)
+{
+}
+
+char *
+bar (void)
+{
+  const char *s = "foo";
+  char *s1 = s;
+  s1 = s;
+  foo (s);
+  return s;
+}
This page took 0.11146 seconds and 5 git commands to generate.