This patch improves the location of the error message about taking the address
of a bit-field.  While at it, I also fixed two other similar spots.

Not a regression, but given its extreme triviality I thought this could have
gone in even at this time.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-04-15  Marek Polacek  <pola...@redhat.com>

        PR c/70671
        * c-typeck.c (build_unary_op): Pass location down to error and
        warning call.

        * gcc.dg/bitfld-22.c: New test.

diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index 9a14994..59a3c61 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -4436,8 +4436,8 @@ build_unary_op (location_t location,
        case COMPONENT_REF:
          if (DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1)))
            {
-             error ("cannot take address of bit-field %qD",
-                    TREE_OPERAND (arg, 1));
+             error_at (location, "cannot take address of bit-field %qD",
+                       TREE_OPERAND (arg, 1));
              return error_mark_node;
            }
 
@@ -4449,15 +4449,16 @@ build_unary_op (location_t location,
              if (!AGGREGATE_TYPE_P (TREE_TYPE (arg))
                  && !VECTOR_TYPE_P (TREE_TYPE (arg)))
                {
-                 error ("cannot take address of scalar with reverse storage "
-                        "order");
+                 error_at (location, "cannot take address of scalar with "
+                           "reverse storage order");
                  return error_mark_node;
                }
 
              if (TREE_CODE (TREE_TYPE (arg)) == ARRAY_TYPE
                  && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (arg)))
-               warning (OPT_Wscalar_storage_order, "address of array with "
-                       "reverse scalar storage order requested");
+               warning_at (location, OPT_Wscalar_storage_order,
+                           "address of array with reverse scalar storage "
+                           "order requested");
            }
 
        default:
diff --git gcc/testsuite/gcc.dg/bitfld-22.c gcc/testsuite/gcc.dg/bitfld-22.c
index e69de29..2fb904b 100644
--- gcc/testsuite/gcc.dg/bitfld-22.c
+++ gcc/testsuite/gcc.dg/bitfld-22.c
@@ -0,0 +1,18 @@
+/* PR c/70671 */
+/* { dg-do compile } */
+
+extern void bar (int *);
+
+struct S
+{
+  int x:2;
+} s, *r;
+
+void
+foo (void)
+{
+  int *p1 = &s.x; /* { dg-error "13:cannot take address of bit-field 'x'" } */
+  int *p2;
+  p2 = &s.x; /* { dg-error "8:cannot take address of bit-field 'x'" } */
+  bar (&s.x); /* { dg-error "8:cannot take address of bit-field 'x'" } */
+}

        Marek

Reply via email to