emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: C mode bug


From: Alan Mackenzie
Subject: Re: Fwd: C mode bug
Date: Sun, 2 Jul 2006 11:41:37 +0100
User-agent: Mutt/1.5.9i

Hi, Paul!

Thanks for reporting this bug.  Here's a fix.

Your 7 lines of code have become cc-mode/test/templates-18.cc in the CC
Mode project.  Thanks!

I now know what an "explicit specialization of a template class" is in
C++.  YUCK!  ;-)

On Sat, Jul 01, 2006 at 12:20:22AM +0300, Paul Pogonyshev wrote:
 
> In template specialization (C++) C mode gives incorrect indentation
> when function name is given on separate line:
 
>   template <>
>   struct test <int>
>   {
>     void
>     function ()
>     { }
>   };
 
> is indented as
 
>   template <>
>   struct test <int>
>   {
>     void
>       function ()
>     { }
>   };
 
> Paul

So, please try this patch out.  Let me know if it doesn't work properly.
Thanks!

Log Message:
cc-engine.el (c-looking-at-decl-block): tolerate empty angle brackets (as
seen in "explicit specialisations" of templates).

Index: cc-engine.el
===================================================================
RCS file: /cvsroot/cc-mode/cc-mode/cc-engine.el,v
retrieving revision 5.539.2.4
retrieving revision 5.539.2.5
diff -C2 -d -r5.539.2.4 -r5.539.2.5
*** cc-engine.el        29 Apr 2006 09:38:21 -0000      5.539.2.4
--- cc-engine.el        1 Jul 2006 21:22:05 -0000       5.539.2.5
***************
*** 4533,4571 ****
          nil)
  
!       (while (and
              (c-syntactic-skip-backward "^<;{}" limit t)
  
!             (if (eq (char-before) ?<)
!                 t
!               ;; Stopped at bob or a char that isn't allowed in an
!               ;; arglist, so we've failed.
!               (goto-char start)
!               nil)
  
!             (if (> (point)
!                    (progn (c-beginning-of-current-token)
!                           (point)))
!                 ;; If we moved then the "<" was part of some
!                 ;; multicharacter token.
!                 t
  
!               (backward-char)
!               (let ((beg-pos (point)))
!                 (if (c-forward-<>-arglist all-types)
!                     (cond ((= (point) start)
!                            ;; Matched the arglist.  Break the while.
!                            (goto-char beg-pos)
!                            nil)
!                           ((> (point) start)
!                            ;; We started from a non-paren ">" inside an
!                            ;; arglist.
!                            (goto-char start)
!                            nil)
!                           (t
!                            ;; Matched a shorter arglist.  Can be a nested
!                            ;; one so continue looking.
!                            (goto-char beg-pos)
!                            t))
!                   t)))))
  
        (/= (point) start))))
--- 4533,4572 ----
          nil)
  
!       (while (progn
              (c-syntactic-skip-backward "^<;{}" limit t)
  
!             (and
!              (if (eq (char-before) ?<)
!                  t
!                ;; Stopped at bob or a char that isn't allowed in an
!                ;; arglist, so we've failed.
!                (goto-char start)
!                nil)
  
!              (if (> (point)
!                     (progn (c-beginning-of-current-token)
!                            (point)))
!                  ;; If we moved then the "<" was part of some
!                  ;; multicharacter token.
!                  t
  
!                (backward-char)
!                (let ((beg-pos (point)))
!                  (if (c-forward-<>-arglist all-types)
!                      (cond ((= (point) start)
!                             ;; Matched the arglist.  Break the while.
!                             (goto-char beg-pos)
!                             nil)
!                            ((> (point) start)
!                             ;; We started from a non-paren ">" inside an
!                             ;; arglist.
!                             (goto-char start)
!                             nil)
!                            (t
!                             ;; Matched a shorter arglist.  Can be a nested
!                             ;; one so continue looking.
!                             (goto-char beg-pos)
!                             t))
!                    t))))))
  
        (/= (point) start))))


-- 
Alan Mackenzie (Munich, Germany)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]