GNU bug report logs - #14005
24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection.

Previous Next

Packages: cc-mode, emacs;

Reported by: Dima Kogan <dima <at> secretsauce.net>

Date: Wed, 20 Mar 2013 08:53:02 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Alan Mackenzie <acm <at> muc.de>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#14005: closed (24.3.50; cc-mode: Incorrectly-indented C code
 (wrong syntax). Test case and bisection.)
Date: Thu, 24 Dec 2015 21:46:01 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 24 Dec 2015 21:47:34 +0000
with message-id <20151224214734.GB5714 <at> acm.fritz.box>
and subject line Re: bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection.
has caused the debbugs.gnu.org bug report #14005,
regarding 24.3.50; cc-mode: Incorrectly-indented C code (wrong syntax). Test case and bisection.
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
14005: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14005
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Dima Kogan <dima <at> secretsauce.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50;
	cc-mode: Incorrectly-indented C code (wrong syntax). Test case and
	bisection.
Date: Tue, 19 Mar 2013 22:48:14 -1000
[Message part 3 (text/plain, inline)]
I'm observing very uninteresting-looking C code get
incorrectly-indented. The sample source file (attached) ends with the
following function:

 static Matrix *NonMaximalSuppression(Matrix *strength, Matrix *orientation)
 {
   int x, y, i, rows = strength->rows, cols = strength->cols;
   int pixels = strength->rows * strength->cols, maximum;
   double str1, str2;              /* interpolated edge strength */
   double a1, a2, b1, b2, c1, c2;  /* nearest pixels' edge strength */
   float ux, uy;                   /* weights of a, b, c, and str */
   double ori, str;       /* strength and orientation at center */
   Matrix *newstrength;

   /* Newstrength holds the NMS'ed strength values */
   newstrength = (Matrix *)malloc(sizeof(Matrix));
   newstrength->rows = strength->rows;
   newstrength->sheets = 1;
   newstrength->cols = strength->cols;
   newstrength->ptr = (double *)calloc(pixels, sizeof(double));

   return(newstrength);
 }

I'm observing that everything after the /* Newstrength .... */ comment
gets "string" syntax, which is incorrect. This can be seen with
(c-guess-basic-syntax). This also causes incorrect indentation of the
empty line before the return statement (TAB there should move to column
2, but it stays at 0).

The full test source file is attached (called "tst.c"). This is a slight
modification of the source from http://ai.stanford.edu/~ruzon/compass/.
This test case is much longer than I'd like, but the bug appears to be
very sensitive to preceding code, so I'm leaving it alone.

To observe the issue, you can run

 $ emacs -Q --batch --eval '(progn (find-file "/tmp/tst.c") (goto-char
 6072) (message "%s" (c-guess-basic-syntax)))

The right answer is "statement", but the current version of emacs says
"string". I did a bisection. This problem was introduced in early 2012
with this commit:

http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=b0b68fedb6a6fe7bc55c1fe4f256bda9a93134b5

This means that all releases of emacs 24 are affected.

Thanks.

[tst.c (text/x-csrc, attachment)]
[Message part 5 (message/rfc822, inline)]
From: Alan Mackenzie <acm <at> muc.de>
To: Dima Kogan <dima <at> secretsauce.net>
Cc: 14005-done <at> debbugs.gnu.org
Subject: Re: bug#14005: 24.3.50; cc-mode: Incorrectly-indented C code (wrong
 syntax). Test case and bisection.
Date: Thu, 24 Dec 2015 21:47:34 +0000
Hello, Dima.

The problem is no longer apparent in the current emacs-25 branch at
savannah, so I'm closing this bug as fixed.

On Tue, Mar 19, 2013 at 10:48:14PM -1000, Dima Kogan wrote:
> I'm observing very uninteresting-looking C code get
> incorrectly-indented. The sample source file (attached) ends with the
> following function:

>  static Matrix *NonMaximalSuppression(Matrix *strength, Matrix *orientation)
>  {
>    int x, y, i, rows = strength->rows, cols = strength->cols;
>    int pixels = strength->rows * strength->cols, maximum;
>    double str1, str2;              /* interpolated edge strength */
>    double a1, a2, b1, b2, c1, c2;  /* nearest pixels' edge strength */
>    float ux, uy;                   /* weights of a, b, c, and str */
>    double ori, str;       /* strength and orientation at center */
>    Matrix *newstrength;

>    /* Newstrength holds the NMS'ed strength values */
>    newstrength = (Matrix *)malloc(sizeof(Matrix));
>    newstrength->rows = strength->rows;
>    newstrength->sheets = 1;
>    newstrength->cols = strength->cols;
>    newstrength->ptr = (double *)calloc(pixels, sizeof(double));

>    return(newstrength);
>  }

> I'm observing that everything after the /* Newstrength .... */ comment
> gets "string" syntax, which is incorrect. This can be seen with
> (c-guess-basic-syntax). This also causes incorrect indentation of the
> empty line before the return statement (TAB there should move to column
> 2, but it stays at 0).

> The full test source file is attached (called "tst.c"). This is a slight
> modification of the source from http://ai.stanford.edu/~ruzon/compass/.
> This test case is much longer than I'd like, but the bug appears to be
> very sensitive to preceding code, so I'm leaving it alone.

> To observe the issue, you can run

>  $ emacs -Q --batch --eval '(progn (find-file "/tmp/tst.c") (goto-char
>  6072) (message "%s" (c-guess-basic-syntax)))

> The right answer is "statement", but the current version of emacs says
> "string". I did a bisection. This problem was introduced in early 2012
> with this commit:

> http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=b0b68fedb6a6fe7bc55c1fe4f256bda9a93134b5

> This means that all releases of emacs 24 are affected.

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).


This bug report was last modified 9 years and 154 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.