In GNU Emacs 23.0.60.1 (i686-pc-linux-gnu, GTK+ Version 2.12.0) of 2008-11-26 on geert-laptop Windowing system distributor `The X.Org Foundation', version 11.0.10300000 When a C/C++ file contains mixed struct/function definitions, which-func-mode gets confused. To reproduce (see also the comments in the test case file): 1. open the test case file whichfunc-testcase.cpp 2. make sure which-func-mode is enabled (M-x which-func-mode) 3. put the point within the funcA() definition 4. the modeline shows "structA", not the expected "funcA" In the following I'll describe the problem in somewhat more detail. In `which-function()' it is assumed that the entries from `imenu--index-alist' are ordered by buffer possition. `which-function()' does a linear search through the items, and as soon as a buffer position is encountered greater than point, the search stops. However, when submenu's are present in `imenu--index-alist', the items are not necessarily ordered by buffer position anymore: For the testcase the imenu--index-alist variable looks like this: (("Class" ("structA" . #) ("structB" . #)) ("funcA" . #) ("funcB" . #)) The attached patch ensures the linear search through `menu--index-alist does not end prematurely, and all items are taken into account. This fixes the problem.