On 06/22/2016 08:52 PM, David Malcolm wrote:
PR c/71613 identifies a problem where we fail to report this enum:

  enum { e1 = LLONG_MIN };

with -pedantic, due to LLONG_MIN being inside a system header.

This patch updates the C and C++ frontends to use the location of the
name as the primary location in the diagnostic, supplying the location
of the value as a secondary location, fixing the issue.

Before:
  $ gcc -c /tmp/test.c -Wpedantic
  /tmp/test.c: In function 'main':
  /tmp/test.c:3:14: warning: ISO C restricts enumerator values to range of 
'int' [-Wpedantic]
     enum { c = -3000000000 };
                ^

After:
  $ ./xgcc -B. -c /tmp/test.c -Wpedantic
  /tmp/test.c: In function 'main':
  /tmp/test.c:3:10: warning: ISO C restricts enumerator values to range of 
'int' [-Wpedantic]
     enum { c = -3000000000 };
            ^   ~~~~~~~~~~~

Successfully bootstrapped&regretested on x86_64-pc-linux-gnu;
adds 13 PASS results to gcc.sum and 9 PASS results to g++.sum.

OK for trunk?

gcc/c/ChangeLog:
        PR c/71610
        PR c/71613
        * c-decl.c (build_enumerator): Fix description of LOC in comment.
        Update diagnostics to use a rich_location at decl_loc, rather than
        at loc, adding loc as a secondary range if available.
        * c-parser.c (c_parser_enum_specifier): Use the full location of
        the expression for value_loc, rather than just the first token.

gcc/cp/ChangeLog:
        PR c/71610
        PR c/71613
        * cp-tree.h (build_enumerator): Add location_t param.
        * decl.c (build_enumerator): Add "value_loc" param.  Update
        "not an integer constant" diagnostic to use "loc" rather than
        input_location, and to add "value_loc" as a secondary range if
        available.
        * parser.c (cp_parser_enumerator_definition): Extract the
        location of the value from the cp_expr for the constant
        expression, if any, and pass it to build_enumerator.
        * pt.c (tsubst_enum): Extract EXPR_LOCATION of the value,
        and pass it to build_enumerator.

gcc/ChangeLog:
        PR c/71610
        PR c/71613
        * diagnostic-core.h (pedwarn_at_rich_loc): New prototype.
        * diagnostic.c (pedwarn_at_rich_loc): New function.

gcc/testsuite/ChangeLog:
        PR c/71610
        PR c/71613
        * c-c++-common/pr71610.c: New test case.
        * gcc.dg/c90-const-expr-8.c: Update expected column of diagnostic.
        * gcc.dg/pr71610-2.c: New test case.
        * gcc.dg/pr71613.c: New test case.
OK.

jeff

Reply via email to