https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117629

--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalc...@gcc.gnu.org>:

https://gcc.gnu.org/g:321983033d621e3f75e11d380c4463956a3f6e1e

commit r15-6507-g321983033d621e3f75e11d380c4463956a3f6e1e
Author: David Malcolm <dmalc...@redhat.com>
Date:   Thu Jan 2 15:10:15 2025 -0500

    c: special-case some "bool" errors with C23 (v2) [PR117629]

    Changed in v2:
    - distinguish between "bool" and "_Bool" when determining
      standard version

    This patch attempts to provide better error messages for
    code compiled with C23 that hasn't been updated for
    "bool", "true", and "false" becoming keywords.

    Specifically:

    (1) with "typedef int bool;" previously we emitted:

    t1.c:7:13: error: two or more data types in declaration specifiers
        7 | typedef int bool;
          |             ^~~~
    t1.c:7:1: warning: useless type name in empty declaration
        7 | typedef int bool;
          | ^~~~~~~

    whereas with this patch we emit:

    t1.c:7:13: error: 'bool' cannot be defined via 'typedef'
        7 | typedef int bool;
          |             ^~~~
    t1.c:7:13: note: 'bool' is a keyword with '-std=c23' onwards
    t1.c:7:1: warning: useless type name in empty declaration
        7 | typedef int bool;
          | ^~~~~~~

    (2) with "int bool;" previously we emitted:

    t2.c:7:5: error: two or more data types in declaration specifiers
        7 | int bool;
          |     ^~~~
    t2.c:7:1: warning: useless type name in empty declaration
        7 | int bool;
          | ^~~

    whereas with this patch we emit:

    t2.c:7:5: error: 'bool' cannot be used here
        7 | int bool;
          |     ^~~~
    t2.c:7:5: note: 'bool' is a keyword with '-std=c23' onwards
    t2.c:7:1: warning: useless type name in empty declaration
        7 | int bool;
          | ^~~

    (3) with "typedef enum { false = 0, true = 1 } _Bool;" previously we
    emitted:

    t3.c:7:16: error: expected identifier before 'false'
        7 | typedef enum { false = 0, true = 1 } _Bool;
          |                ^~~~~
    t3.c:7:38: error: expected ';', identifier or '(' before '_Bool'
        7 | typedef enum { false = 0, true = 1 } _Bool;
          |                                      ^~~~~
    t3.c:7:38: warning: useless type name in empty declaration

    whereas with this patch we emit:

    t3.c:7:16: error: cannot use keyword 'false' as enumeration constant
        7 | typedef enum { false = 0, true = 1 } _Bool;
          |                ^~~~~
    t3.c:7:16: note: 'false' is a keyword with '-std=c23' onwards
    t3.c:7:38: error: expected ';', identifier or '(' before '_Bool'
        7 | typedef enum { false = 0, true = 1 } _Bool;
          |                                      ^~~~~
    t3.c:7:38: warning: useless type name in empty declaration

    gcc/c/ChangeLog:
            PR c/117629
            * c-decl.cc (declspecs_add_type): Special-case attempts to use
            bool as a typedef name or declaration name.
            * c-errors.cc (get_std_for_keyword): New.
            (add_note_about_new_keyword): New.
            * c-parser.cc (report_bad_enum_name): New, split out from...
            (c_parser_enum_specifier): ...here, adding handling for RID_FALSE
            and RID_TRUE.
            * c-tree.h (add_note_about_new_keyword): New decl.

    gcc/testsuite/ChangeLog:
            PR c/117629
            * gcc.dg/auto-type-2.c: Update expected output with _Bool.
            * gcc.dg/c23-bool-errors-1.c: New test.
            * gcc.dg/c23-bool-errors-2.c: New test.
            * gcc.dg/c23-bool-errors-3.c: New test.

    Signed-off-by: David Malcolm <dmalc...@redhat.com>
  • [Bug c/117629] Redefinition of ... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to