From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#23775: 25.0.95.2; c-mode: Incorrect indentation and function bundery detection Date: 16 Jun 2016 09:18:39 -0000 Organization: muc.de e.V. Message-ID: <20160616091839.6925.qmail__31295.7325172194$1466070036$gmane$org@mail.muc.de> References: <8760tac594.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1466070036 32641 80.91.229.3 (16 Jun 2016 09:40:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jun 2016 09:40:36 +0000 (UTC) Cc: Rolf Ade To: 23775@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 16 11:40:22 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bDTmg-0007ET-09 for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Jun 2016 11:40:22 +0200 Original-Received: from localhost ([::1]:47617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDTmf-0008Up-8H for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Jun 2016 05:40:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDTS5-0003z8-CI for bug-gnu-emacs@gnu.org; Thu, 16 Jun 2016 05:19:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDTS2-0001He-5s for bug-gnu-emacs@gnu.org; Thu, 16 Jun 2016 05:19:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDTS2-0001Ha-2B; Thu, 16 Jun 2016 05:19:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bDTS1-0003wr-T9; Thu, 16 Jun 2016 05:19:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Thu, 16 Jun 2016 09:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23775 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 23775-submit@debbugs.gnu.org id=B23775.146606872815146 (code B ref 23775); Thu, 16 Jun 2016 09:19:01 +0000 Original-Received: (at 23775) by debbugs.gnu.org; 16 Jun 2016 09:18:48 +0000 Original-Received: from localhost ([127.0.0.1]:42891 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDTRn-0003wE-O5 for submit@debbugs.gnu.org; Thu, 16 Jun 2016 05:18:47 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:44357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDTRi-0003vv-VN for 23775@debbugs.gnu.org; Thu, 16 Jun 2016 05:18:46 -0400 Original-Received: (qmail 6927 invoked by uid 3782); 16 Jun 2016 09:18:39 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.3-RELEASE-p4 (amd64)) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:119621 Archived-At: Hello, Rolf. In article 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).