unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* - c-end-of-defun - !
@ 2007-04-18 13:17 A Soare
  2007-04-18 18:38 ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: A Soare @ 2007-04-18 13:17 UTC (permalink / raw)
  To: Emacs   Dev  [emacs-devel]


int
function (void)
{
    int b;
    
}

struct ONE function (void)
{
    int a;
    
}

struct
TWO function (void)
{
    int a;
    
}


Here are 3 valid functions written in C.
Copy them into a buffer in C-MODE, and eval (end-of defun) in the first one and in the second.

In the second case => FAIL.

That is because of this code in c-end-of-defun:

    ;; Do we need to move forward from the brace to the semicolon?
    (when (eq arg 0)
      (if (c-in-function-trailer-p)	; after "}" of struct/enum, etc.
	  (c-syntactic-re-search-forward ";"))



(c-in-function-trailer-p) in our case MUST return NULL. Not the (point).

Is really need to call (c-syntactic-re-search-forward ";") here?


Alin Soare.

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

* Re: - c-end-of-defun - !
  2007-04-18 13:17 - c-end-of-defun - ! A Soare
@ 2007-04-18 18:38 ` Alan Mackenzie
  0 siblings, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2007-04-18 18:38 UTC (permalink / raw)
  To: A Soare, Andreas Schwab; +Cc: bug-cc-mode, Chong Yidong, emacs-devel

'evening, Alin and Andreas!

Thank you both very much for reporting this bug!  (Andreas: the bug you
reported 2 hours after Alin is the same bug.)

On Wed, Apr 18, 2007 at 03:17:00PM +0200, A Soare wrote:
> 
> int
> function (void)
> {
>     int b;
>     
> }

> struct ONE function (void)
> {
>     int a;
>     
> }

> struct
> TWO function (void)
> {
>     int a;
>     
> }

> 
> Here are 3 valid functions written in C.
> Copy them into a buffer in C-MODE, and eval (end-of defun) in the first one and in the second.

> In the second case => FAIL.
 
> That is because of this code in c-end-of-defun:
> 
>     ;; Do we need to move forward from the brace to the semicolon?
>     (when (eq arg 0)
>       (if (c-in-function-trailer-p)	; after "}" of struct/enum, etc.
> 	  (c-syntactic-re-search-forward ";"))
 
> (c-in-function-trailer-p) in our case MUST return NULL. Not the (point).
 
This is indeed the case.  
 
> Is really need to call (c-syntactic-re-search-forward ";") here?
 
Yes.  c-end-of-defun is being fooled by the "struct" in the functions'
return types into thinking the function is actually a struct declaration
like this:

struct foo {
    int bar ;
    int baz ;
} blorg ;

A struct also counts as a defun, and it ends at the first semicolon
following the brace (as contrasted with a function, which ends at the
brace).  This is what the (c-syntactic-re-search-forward ";") is for.

The solution is to analyse the defuns' headers more thoroughly.  It
shouldn't be too hard, and shouldn't take too long.

> Alin Soare.

-- 
Alan Mackenzie (Ittersbach, Germany)

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

* Re: - c-end-of-defun - !
@ 2007-04-18 19:36 A Soare
  0 siblings, 0 replies; 3+ messages in thread
From: A Soare @ 2007-04-18 19:36 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Emacs   Dev  [emacs-devel]


Shell I do the patch tomorrow? Or it has already been done?

A Soare.

> Message du 18/04/07 à 20h38
> De : "Alan Mackenzie" <acm@muc.de>
> A : "A Soare" <alinsoar@voila.fr>, "Andreas Schwab" <schwab@suse.de>
> Copie à : "Chong Yidong" <cyd@stupidchicken.com>, emacs-devel@gnu.org, bug-cc-mode@gnu.org
> Objet : Re: - c-end-of-defun - !
> 
> 'evening, Alin and Andreas!
> 
> Thank you both very much for reporting this bug!  (Andreas: the bug you
> reported 2 hours after Alin is the same bug.)
> 
> On Wed, Apr 18, 2007 at 03:17:00PM +0200, A Soare wrote:
> > 
> > int
> > function (void)
> > {
> >     int b;
> >     
> > }
> 
> > struct ONE function (void)
> > {
> >     int a;
> >     
> > }
> 
> > struct
> > TWO function (void)
> > {
> >     int a;
> >     
> > }
> 
> > 
> > Here are 3 valid functions written in C.
> > Copy them into a buffer in C-MODE, and eval (end-of defun) in the first one and in the second.
> 
> > In the second case => FAIL.
>  
> > That is because of this code in c-end-of-defun:
> > 
> >     ;; Do we need to move forward from the brace to the semicolon?
> >     (when (eq arg 0)
> >       (if (c-in-function-trailer-p)	; after "}" of struct/enum, etc.
> > 	  (c-syntactic-re-search-forward ";"))
>  
> > (c-in-function-trailer-p) in our case MUST return NULL. Not the (point).
>  
> This is indeed the case.  
>  
> > Is really need to call (c-syntactic-re-search-forward ";") here?
>  
> Yes.  c-end-of-defun is being fooled by the "struct" in the functions'
> return types into thinking the function is actually a struct declaration
> like this:
> 
> struct foo {
>     int bar ;
>     int baz ;
> } blorg ;
> 
> A struct also counts as a defun, and it ends at the first semicolon
> following the brace (as contrasted with a function, which ends at the
> brace).  This is what the (c-syntactic-re-search-forward ";") is for.
> 
> The solution is to analyse the defuns' headers more thoroughly.  It
> shouldn't be too hard, and shouldn't take too long.
> 
> > Alin Soare.
> 
> -- 
> Alan Mackenzie (Ittersbach, Germany)
> 
>

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

end of thread, other threads:[~2007-04-18 19:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-18 13:17 - c-end-of-defun - ! A Soare
2007-04-18 18:38 ` Alan Mackenzie
  -- strict thread matches above, loose matches on Subject: below --
2007-04-18 19:36 A Soare

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).