bug#64322: CC Mode 5.35.2 (C/*l); More incorrect type recognition

Alan Mackenzie <[email protected]> Fri, 30 Jun 2023 19:47:05 +0000
Newsgroups gmane.emacs.cc-mode.general
Message-ID <ZJ8xOd3DXVHbdfMd@ACM>
Hello, Po.

On Wed, Jun 28, 2023 at 15:05:03 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> I just encountered a new instance of CC Mode misrecognizing identifiers
> as types.  In a C Mode buffer, insert:

> void
> add_property (name, expression)

> then, type:

> RET TAB s t r u c t SPC e x p r e s s i o n SPC e x p r e s s i o n ;

> `expression' will then be fontified as a type within the function
> declarator's identifier list!

Yes.  The problem was a confusion between C++ and C regarding type
definition.  In C++, "class Foo" or "struct Foo" defines a type "Foo".
In C, in "struct Foo", there is no such type defined, "Foo" is merely a
struct tag.

This involves a one line fix in cc-langs.el, to remove items from the
lang const c-typeless-decl-kwds.  Additionally, I've corrected an
unrelated typo in cc-fonts.el.

Would you please try out the attached patch in your real code
thoroughly, and either confirm the bug is fixed, or tell me what's still
wrong.  Thanks!

> Thanks in advance.

> Emacs  : GNU Emacs 29.0.92 (build 1, x86_64-pc-linux-gnu)
>  of 2023-06-25
> Package: CC Mode 5.35.2 (C/*l)
> Buffer Style: gnu
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)

-- 
Alan Mackenzie (Nuremberg, Germany).
diff.20230630.diff (text/plain, 904 B)
diff -r 0e3ab44d5a46 cc-fonts.el
--- a/cc-fonts.el	Wed Jun 28 18:17:13 2023 +0000
+++ b/cc-fonts.el	Fri Jun 30 19:25:37 2023 +0000
@@ -2309,7 +2309,7 @@
 		     (c-forward-syntactic-ws))
 		   (goto-char (match-end ,type-match))))))))
 
-      ;; Fontify special declarations that lacks a type.
+      ;; Fontify special declarations that lack a type.
       ,@(when (c-lang-const c-typeless-decl-kwds)
 	  `((,(c-make-font-lock-search-function
 	       (concat "\\<\\("
diff -r 0e3ab44d5a46 cc-langs.el
--- a/cc-langs.el	Wed Jun 28 18:17:13 2023 +0000
+++ b/cc-langs.el	Fri Jun 30 19:25:37 2023 +0000
@@ -2584,6 +2584,7 @@
   ;; {...}").
   t    (append (c-lang-const c-class-decl-kwds)
 	       (c-lang-const c-brace-list-decl-kwds))
+  (c objc) nil
   ;; Note: "manages" for CORBA CIDL clashes with its presence on
   ;; `c-type-list-kwds' for IDL.
   idl  (append (c-lang-const c-typeless-decl-kwds)