Menu

#381 C++ Return type on separate line is discarded

open
nobody
None
5
2019-11-19
2019-11-18
No

Functions with the return type on a separate line lose the return type.

Example:

int
foo() {
}

gives you:

foo t.ino /^foo() {$/;" kind:f line:2 signature:()

whereas it really should give you:

foo t.ino   /^int foo() {$/;"   kind:f  line:2  signature:()

Or at least an optional field:

foo t.cpp   /^foo() {$/;"   kind:f  line:2  signature:() return:int

Discussion

  • Masatake YAMATO

    Masatake YAMATO - 2019-11-19

    /^int foo() {$/

    ctags should not give this.
    A tool reading tags file like vim recognizes the substring between / and / as a regular expression pattern. ^ int foo() {$ doesn't match any substring in the original input.
    I'm not sure that the tool can handle ^ int\nfoo() {$. However, I guess it cannot. At least the new pattern including \n may break compatiblities.

    foo t.cpp /^foo() {$/;" kind:f line:2 signature:() return:int

    The tool can handle this one well. Unofficial fork maintained at https://ctags.io does what you expect:

    [yamato@slave]~/var/ctags-github% ./ctags --version
    ./ctags --version
    Universal Ctags 0.0.0(2baef0d3), Copyright (C) 2015 Universal Ctags Team
    Universal Ctags is derived from Exuberant Ctags.
    Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
      Compiled: Nov 10 2019, 11:25:16
      URL: https://ctags.io/
      Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +aspell, +packcc
    [yamato@slave]~/var/ctags-github% cat /tmp/foo.c 
    cat /tmp/foo.c 
    int
    foo() {
    }
    [yamato@slave]~/var/ctags-github% ./ctags -o - --fields=+s /tmp/foo.c
    ./ctags -o - --fields=+s /tmp/foo.c
    foo /tmp/foo.c  /^foo() {$/;"   f   language:C  typeref:typename:int
    [yamato@slave]~/var/ctags-github% ./ctags -o - --fields=+S /tmp/foo.c
    ./ctags -o - --fields=+S /tmp/foo.c
    foo /tmp/foo.c  /^foo() {$/;"   f   language:C  typeref:typename:int    signature:()
    

    typeref is used instad of return.

     
    • Majenko Technologies

      Great, thanks. I shall look at ctags.io. FYI, I'm using ctags to build a list of available functions in a GUI and need the return type. Also the same information is used to automatically populate a header file with function prototypes, and without the return type it breaks the code.

       

Log in to post a comment.

MongoDB Logo MongoDB