Subject: Re: bug#55230: CC Mode 5.35.1 (C++//l); Cache inconsistency

From: Alan Mackenzie <[email-masked]>
Date: Tue, 3 May 2022 18:10:36 +0000

Hello, Michael.

On Mon, May 02, 2022 at 15:30:09 -0400, Michael Welsh Duggan wrote:
> Package: cc-mode

> From emacs -Q:

> C-x C-f /tmp/foo.cpp RET
> M-x c-toggle-parse-state-debug RET
> "{}

> After typing the close brace, I get the following:
> c-parse-state inconsistency at 3: using cache: (2), from scratch: nil.  POINT-MIN: 1
> Old state:
> (setq c-state-cache '(2)  c-state-cache-good-pos 1  c-state-nonlit-pos-cache nil  c-state-nonlit-pos-cache-limit 0  c-state-brace-pair-desert nil  c-state-point-min 1  c-state-point-min-lit-type nil  c-state-point-min-lit-start nil  c-state-min-scan-pos 1  c-state-old-cpp-beg nil  c-state-old-cpp-end nil  c-parse-state-point 3)

> I have not noticed any indentation errors due to this, but any cache
> inconsistency might lead to errors down the line, hence this report.

Many thanks for the bug report.

This time it is not the cache mechanism itself which is at fault.
Instead, it is the first character ", which since it is unbalanced by
another ", has had its syntax is temporarily "commented out" by giving
it a syntax-table property of "punctuation".  The parse-state cache was
generated whilst in this state, but used when it no longer was, hence
the inconsistency.

There are somewhere between 10 and 20 occurrences of c-parse-state in
the source code which will need to be "protected" against this fault.  I
hope to be able to finish this work in the next two or three days, when
I'll get back to you again.

> Emacs  : GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0)
>  of 2022-04-09
> Package: CC Mode 5.35.1 (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 1-bit)

[ CC Mode state dump appreciated, but snipped. ]

> -- 
> Michael Welsh Duggan
> ([email-masked])

-- 
Alan Mackenzie (Nuremberg, Germany).