C-family, Objective-C [1/3] : Implement Wobjc-root-class [PR77404].
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 25 Oct 2020 07:49:16 +0000 (07:49 +0000)
committerIain Sandoe <iain@sandoe.co.uk>
Fri, 13 Nov 2020 10:39:48 +0000 (10:39 +0000)
commit3fe07cdec8c79bce53ea5aeb8e607df6eb5c8c2c
tree989f0b35f1a61b36a0bfc388398ec51850bf1de3
parent4852c3266ec0887316b9fbbb106b8540e3e948d6
C-family, Objective-C [1/3] : Implement Wobjc-root-class [PR77404].

This warning catches the case that the user has left the
superclass specification from a class interface.  Root
classes are, of course, permitted and an attribute is added
to mark these so that the diagnostic is suppressed.

The warning and attribute spellings have been kept in sync
with the language reference implementation (clang).

The diagnostic location information present in the objective-c
interface and class definitions is relatively poor.  This patch
adds a location for the class name to the interface and makes use
of it in existing warnings.

Part 1 is the changes to code and added tests.

Many entries in the testsuite make use of root classes so
there are a large number of mechanical changes there adding
"-Wno-objc-root-class" to the options.

The test changes are parts 2 (objective-c) and 3 (objective-c++)
in the patch series.

gcc/c-family/ChangeLog:

PR objc/77404
* c-attribs.c (handle_objc_root_class_attribute): New
* c-objc.h (objc_start_class_interface): Add a location
value for the position of the class name.
* c.opt: Add Wobjc-root-class.
* stub-objc.c (objc_start_class_interface): Add a location
value for the position of the class name.

gcc/c/ChangeLog:

PR objc/77404
* c-parser.c (c_parser_objc_class_definition): Pass the
location of the class name to the interface declaration.

gcc/cp/ChangeLog:

PR objc/77404
* parser.c (cp_parser_objc_class_interface): Pass the
location of the class name to the interface declaration.

gcc/objc/ChangeLog:

PR objc/77404
* objc-act.c (objc_start_class_interface): Accept the location
of the class name, use it in existing diagnostic.
(start_class): Accept obj_root_class type attributes.  Warn when
the interface for an implementation does not contain a super
class (unless the diagnostic is suppressed by the the command
line flag or the objc_root_class type attribute).

gcc/testsuite/ChangeLog:

PR objc/77404
* objc.dg/attributes/root-class-01.m: New test.
* objc.dg/root-class-00.m: New test.
* obj-c++.dg/attributes/root-class-01.mm: New test.
* obj-c++.dg/root-class-00.mm: New test.

gcc/ChangeLog:

PR objc/77404
* doc/extend.texi: Document the objc_root_class attribute.
* doc/invoke.texi: Document -Wobjc-root-class.
13 files changed:
gcc/c-family/c-attribs.c
gcc/c-family/c-objc.h
gcc/c-family/c.opt
gcc/c-family/stub-objc.c
gcc/c/c-parser.c
gcc/cp/parser.c
gcc/doc/extend.texi
gcc/doc/invoke.texi
gcc/objc/objc-act.c
gcc/testsuite/obj-c++.dg/attributes/root-class-01.mm [new file with mode: 0644]
gcc/testsuite/obj-c++.dg/root-class-00.mm [new file with mode: 0644]
gcc/testsuite/objc.dg/attributes/root-class-01.m [new file with mode: 0644]
gcc/testsuite/objc.dg/root-class-00.m [new file with mode: 0644]