unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection
@ 2016-06-16  1:05 Rolf Ade
  2016-06-16  1:34 ` Noam Postavsky
       [not found] ` <mailman.1576.1466039228.1216.bug-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Rolf Ade @ 2016-06-16  1:05 UTC (permalink / raw)
  To: 23775


emacs -Q

Open some empty buffer foo.c and put it into c-mode if already is
(M-x c-mdoe). Insert this C code into it:

#define foo
int main (void) {
  int a=0;
  int b=0;
#ifdef foo
  if (a==0) {
#else
    if (b==0) {
#endif
      return 0;
    }
  }

I've inserted it here as emacs -Q indents it, this is the indentation
part of the report.

Place the point at the beginning of function foo, then call
c-end-of-defun, C-M-e by default in emacs -Q. Bell rings, point is
before the last charater of the first line of main, here:

int main (void) _P_{

(which is clearly not the end of the function) and prompts me in the
mini-buffer: "forward-sexp: Scan error: "Unbalanced parentheses", 29,
133"

However well advised such code is, gcc foo.c just compilies.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection
  2016-06-16  1:05 Rolf Ade
@ 2016-06-16  1:34 ` Noam Postavsky
       [not found] ` <mailman.1576.1466039228.1216.bug-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Noam Postavsky @ 2016-06-16  1:34 UTC (permalink / raw)
  To: Rolf Ade; +Cc: 23775

On Wed, Jun 15, 2016 at 9:05 PM, Rolf Ade <rolf@pointsman.de> wrote:
> However well advised such code is, gcc foo.c just compilies.

s/well/ill/? gcc compiles the below as well, but IMO you can't expect
Emacs to be able to properly handle every horrible trick that's
possible with the preprocessor.

#define BEGIN {
#define STOP ;

int main() BEGIN
  int a, b STOP
  if (a == 0) BEGIN
        if (b==0) {
          return 0 STOP
            }
}
}





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection
       [not found] ` <mailman.1576.1466039228.1216.bug-gnu-emacs@gnu.org>
@ 2016-06-16  9:18   ` Alan Mackenzie
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2016-06-16  9:18 UTC (permalink / raw)
  To: 23775; +Cc: Rolf Ade

Hello, Rolf.
In article <mailman.1576.1466039228.1216.bug-gnu-emacs@gnu.org> you wrote:

> emacs -Q

> Open some empty buffer foo.c and put it into c-mode if already is
> (M-x c-mdoe). Insert this C code into it:

> #define foo
> int main (void) {
>   int a=0;
>   int b=0;
> #ifdef foo
>   if (a==0) {
> #else
>     if (b==0) {
> #endif
>       return 0;
>     }
>   }

> I've inserted it here as emacs -Q indents it, this is the indentation
> part of the report.

> Place the point at the beginning of function foo, then call
> c-end-of-defun, C-M-e by default in emacs -Q. Bell rings, point is
> before the last charater of the first line of main, here:

> int main (void) _P_{

> (which is clearly not the end of the function) and prompts me in the
> mini-buffer: "forward-sexp: Scan error: "Unbalanced parentheses", 29,
> 133"

> However well advised such code is, gcc foo.c just compilies.

Yes, this has come up before.  Unbalanced braces in preprocessor
statements[*] are horrendously difficult to parse - what should be done, for
example, when two arms of a #if construct have different numbers of
braces?

[*] ...by which I mean the part inside a particular arm of a preprocessor
conditional has unbalanced braces.

I tried once before to solve this problem, but didn't get very far.  What
was obvious, at the time, was that a solution would slow CC Mode down,
possibly quite a bit.

So, we've collectively decided that this bug, although real, won't be
fixed.  The best advice we can give is to arrange the C code such that
unbalanced braces in #if arms don't happen.

Sorry.

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection
       [not found] <20160616091839.6925.qmail@mail.muc.de>
@ 2016-06-21 23:16 ` Rolf Ade
  0 siblings, 0 replies; 4+ messages in thread
From: Rolf Ade @ 2016-06-21 23:16 UTC (permalink / raw)
  To: Alan Mackenzie, 23775


Hello Alan,

Am 06/16/2016 11:18 AM, Alan Mackenzie wrote:
> [...]
> I tried once before to solve this problem, but didn't get very far.  What
> was obvious, at the time, was that a solution would slow CC Mode down,
> possibly quite a bit.
>
> So, we've collectively decided that this bug, although real, won't be
> fixed.  The best advice we can give is to arrange the C code such that
> unbalanced braces in #if arms don't happen.
>
> Sorry.

Just for the record: I stumbled about that in the wild. This function:
http://core.tcl.tk/tdom/artifact/3a53ac985a15644d?ln=2142-2535
triggers the bug.

I stripped down to a minimal example from that, not from the idea to
do "preprocessor tricks" to fool c-mode.







^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-21 23:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20160616091839.6925.qmail@mail.muc.de>
2016-06-21 23:16 ` bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection Rolf Ade
2016-06-16  1:05 Rolf Ade
2016-06-16  1:34 ` Noam Postavsky
     [not found] ` <mailman.1576.1466039228.1216.bug-gnu-emacs@gnu.org>
2016-06-16  9:18   ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).