#912 C++11 Alias template highlighting failure

open-accepted
nobody
Interface (176)
5
2012-10-30
2012-10-29
No

c++11 introduced alias templates, see http://en.wikipedia.org/wiki/C%2B%2B11#Alias_templates

Geany 1.23 (git 2109677) does not handle its highlighting properly, see the attached image.

(Ubuntu Linux 11.04, kernel 2.6.38-13 (no, I am not allowed to upgrade :) )

Related

Bugs: #907

Discussion

  • Rody Oldenhuis

    Rody Oldenhuis - 2012-10-29

    Alias template highlight failure

     
  • Lex Trotman

    Lex Trotman - 2012-10-30

    As your example shows, the using syntax can be used for both normal type aliasing and template aliasing.

    The former should be easy to handle as it is equivalent to a typedef.

    Templates are not really properly handled by the ctags parsers (and hence by Geany). A template name is not a type, the instantiated class_name<parameters> is the typename. The C++11 standard explicitly uses template_id for the uninstantiated entity and it probably should be highlighted differently. And of course function templates don't define typenames.

    Its not clear to me if the using template alias syntax can be used for function templates also, the standard does not seem to exclude such a use, so the parser would need to know what the type declaration referred to, to correctly determine the kind of the alias.

    Also the using declaration to import names into classes does not seem to work, but I am not sure I totally understand teh semantics of that.

     
  • Lex Trotman

    Lex Trotman - 2012-10-30
    • status: open --> open-accepted
     
  • Colomban Wendling

    Attached are 2 files: a proposed patch and a sample test file I did for… testing. I don't really know the depths of C++, so I'd prefer to see some testing before committing this, to make sure it's doesn't break obvious things and works approximately correctly. So please test (especially you, elextr ;)).

    > The former should be easy to handle as it is equivalent to a typedef.

    Or not, the syntax has nothing to do with typedefs, it's not like "using" was an alias of "typedef".

    > Templates are not really properly handled by the ctags parsers (and
    > hence by Geany). A template name is not a type, the instantiated
    > class_name<parameters> is the typename.

    Do we really care? If you want completion for "template<typename T> class X { … }" you don't really mind T, you want to get "…" actually; so we need to resolve "X<foo>" as X. Or we'd need to either generate a tag for each and every possible type of T (hahaha) or have complete support for templates everywhere so we know that in "X<foo>" we don't mind the "<foo>" -- and then we could show nice calltips with s/T/foo/g. I doubt anybody wants to spend the time and efforts required for so small gain -- not mentioning that templates is not found in so many languages, so it'd be a very specific thing.

    Though, I'm not a C++ programmer so maybe I underestimate the issue.

    > Also the using declaration to import names into classes does not seem
    > to work, but I am not sure I totally understand teh semantics of that.

    I tested that naively, and it seem to work just fine like the Wikipedia articles says (see the attached test sample).

     
  • Lex Trotman

    Lex Trotman - 2012-10-31

    @colombanw, thank you, tried the patch, attached a slightly extended, commented version of your example file. Has a few funnies, not sure if they are patch related. Note I don't have g++ 4.7 so I can't check it compiles, the using stuff isn't accepted in 4.6.3, and I havn't used C++11 in anger and I said I was not totally sure of the semantics of using.

    So use my comments with caution :)

    > Or not, the syntax has nothing to do with typedefs, it's not like "using"
    was an alias of "typedef".

    The syntax is different but the semantics is the same, thats what I meant. That seems to be what you have done with it :)

    For the "why care about template instantiations" see example added to test file. The specific syntax etc for templates is C++ specific, but the whole idea of generics is available in a number of languages (and Java syntax is similar to C++), but I don't know any of them enough to test.

    > > Also the using declaration to import names into classes does not seem
    > > to work, but I am not sure I totally understand teh semantics of that.

    > I tested that naively, and it seem to work just fine like the Wikipedia
    > articles says (see the attached test sample).

    It didn't and still doesn't, see the comments in the file for clarification (lines 36,37). There are too many uses of using, so we might have been talking about different things :)

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks