]> gcc.gnu.org Git - gcc.git/commit
c++: Improve diagnostics about conflicting specifiers
authorJakub Jelinek <jakub@redhat.com>
Tue, 27 Sep 2022 06:20:05 +0000 (08:20 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 27 Sep 2022 06:21:41 +0000 (08:21 +0200)
commit5b86d5dbe47c477daf739b82c3793a70f8cbd96c
tree2dfad360ac2e4adc7ab68118e8119ae0cf049216
parent5da546d7e0561def07c783e6ec897aaa9e7837c6
c++: Improve diagnostics about conflicting specifiers

On Sat, Sep 17, 2022 at 01:23:59AM +0200, Jason Merrill wrote:
> I wonder why we don't give an error when setting the
> conflicting_specifiers_p flag in cp_parser_set_storage_class?  We should be
> able to give a better diagnostic at that point.

I didn't have time to update the whole patch last night, but this part
seems to be independent and I've managed to test it.

The diagnostics then looks like:
a.C:1:9: error: ‘static’ specifier conflicts with ‘typedef’
    1 | typedef static int a;
      | ~~~~~~~ ^~~~~~
a.C:2:8: error: ‘typedef’ specifier conflicts with ‘static’
    2 | static typedef int b;
      | ~~~~~~ ^~~~~~~
a.C:3:8: error: duplicate ‘static’ specifier
    3 | static static int c;
      | ~~~~~~ ^~~~~~
a.C:4:8: error: ‘extern’ specifier conflicts with ‘static’
    4 | static extern int d;
      | ~~~~~~ ^~~~~~

2022-09-27  Jakub Jelinek  <jakub@redhat.com>

gcc/cp/
* parser.cc (cp_parser_lambda_declarator_opt): Don't diagnose
conflicting specifiers here.
(cp_storage_class_name): New variable.
(cp_parser_decl_specifier_seq): When setting conflicting_specifiers_p
for the first time, diagnose which exact specifiers conflict.
(cp_parser_set_storage_class): Likewise.  Move storage_class
computation earlier.
* decl.cc (grokdeclarator): Don't diagnose conflicting specifiers
here, just return error_mark_node.
gcc/testsuite/
* g++.dg/diagnostic/conflicting-specifiers-1.C: Adjust expected
diagnostics.
* g++.dg/parse/typedef8.C: Likewise.
* g++.dg/parse/crash39.C: Likewise.
* g++.dg/other/mult-stor1.C: Likewise.
* g++.dg/cpp2a/constinit3.C: Likewise.
gcc/cp/decl.cc
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp2a/constinit3.C
gcc/testsuite/g++.dg/diagnostic/conflicting-specifiers-1.C
gcc/testsuite/g++.dg/other/mult-stor1.C
gcc/testsuite/g++.dg/parse/crash39.C
gcc/testsuite/g++.dg/parse/typedef8.C
This page took 0.065817 seconds and 6 git commands to generate.