[C++] Highlight issues with "using" keyword and variables. #1251

Closed
yunkot opened this Issue Apr 22, 2016 · 15 comments

Projects

None yet

3 participants

@yunkot
yunkot commented Apr 22, 2016

C++11 and newer code that uses "using" keyword for type alias is not highlighted, for instance:
codelite hightlight issues 06

Note that "typedef" declaration on image above gets properly highlighted, whereas "using" is not.

Also, function parameters seem to be colored inconsistently. This is probably similar to issue #1077. For example:
codelite highlight issue 07
On image above, note that each "Color", "Gray" and "Alpha" function parameters have their unique color. IMHO, all three should be blue similar to local parameters.

@eranif
Owner
eranif commented Apr 22, 2016

For the latter (inconsistent coloring) there is probably a class named Color somewhere in the workspace, so CodeLite coloured it in green

@yunkot
yunkot commented Apr 22, 2016

No, "Color" is not declared anywhere as a data type. In fact, searching for "Color" in header only finds functions which has "Color" as parameter. I tried declaring something like (which doesn't compile, of course): "Color test" and then right-clicking on "Color" to "Find declaration" - it does nothing.

The following headers are used (all of which are just from stdc++):

#include <cstdint>
#include <cstdbool>
#include <ctgmath>
#include <limits>
#include <type_traits>
#include <algorithm>
#include <exception>

In a new console C++ project, this is how function gets colored:
codelite highlight issues 08

Maybe "Color" data type is pulled off from somewhere by syntax highlighter or even hard-coded?

@eranif
Owner
eranif commented Apr 22, 2016

Nothing is hard coded, it is pulled from somewhere...

@yunkot
yunkot commented Apr 22, 2016 edited

I still haven't been able to find why CodeLite highlighter recognizes "Color" as some valid data type. Perhaps it finds declaration somewhere (other than stdc++, that's for sure), doesn't take scoping into account and continues to accumulate data types? For instance, this seems to paint "MyInt2" in blue even outside of its scope, when data type no longer exists:
codelite highlight issues 10

In addition to issue described in first post, C++11 "auto" variables are not painted in any color:
codelite highlight issue 09

One more highlighting issue with variables:
codelite hightlight issue 11
(if initializer is removed, variables are highlighted correctly)

@yunkot
yunkot commented May 6, 2016 edited

There is one more C+11 highlight issue. "constexpr" constants are not highlighted:

codelite constexpr highlight issue
Note that in above example, "static uint32_t const constexpr test2" is also valid, since after C++14, constexpr does not necessarily imply const.

"constexpr" functions are also affected:
codelite constexpr functions

@yunkot
yunkot commented Jun 4, 2016

FYI, C+11 "override" keyword does not appear to be colored - it just appears white. Shouldn't it be purple like "constexpr"?

@eranif
Owner
eranif commented Jul 21, 2016

One comment: Please use text based examples rather than images - I can't copy them to the clipboard

@eranif eranif closed this in 8bef111 Jul 21, 2016
@dobragab
dobragab commented Sep 26, 2016 edited

Hello,

I think the "using" part isn't fixed properly. I've just pulled from git and built CodeLite (on Arch Linux, using AUR).

Consider this code snippet:

using Type1 = int;
typedef int Type2;

Type1 t1;
Type2 t2;

Type1 and Type2 should be colored same. However, this is not the case, in any of the built-in color themes, as if this "using" wasn't identified as a typedef. For example, this is the result with Monokai_v2.

screenshot from 2016-09-26 12-47-20

@yunkot
yunkot commented Sep 26, 2016

No it doesn't seem to be fixed, at least not in latest weekly build, which claims that it was. In fact, several other issues mentioned here still persist. Relevant code examples, the coloring of which wasn't fixed:

using MyInt_Using = int32_t;
MyInt_Using test1 = 5; // test1 not colored properly

auto const startTicks = getTickCount(); // startTicks not colored properly

int32_t constexpr sum(int a, int b) // sum not colored properly
{
  return a + b;
}

struct A
{
  virtual int32_t test() = 0;
}

struct B : public A
{
  int32_t test() override; // override not colored properly
}

{
  typedef uint32_t MyInt3;
}
MyInt3 someInt = 25; // MyInt3 is colored, but since it no longer exists, it shouldn't.
@eranif
Owner
eranif commented Sep 26, 2016 edited

You are assuming that the syntax highlight is "scope" aware - it is not.
Its just a way of colouring some interesting words in the document.

{
  typedef uint32_t MyInt3;
}
MyInt3 someInt = 25; // MyInt3 is colored, but since it no longer exists, it shouldn't.

Will always be coloured, since the editor component colour words per document
It does not contain list of words to colour per position.

@eranif eranif added a commit that referenced this issue Sep 26, 2016
@eranif Fixed: #1251
 support more cases like: "using MyInt_Using = int32_t" and right side 'const'
6a11257
@dobragab
dobragab commented Sep 26, 2016 edited

Seems like 6a11257 solved this, now it looks as intended in the fresh build. Thank you!

@yunkot
yunkot commented Sep 27, 2016

Is there any chance to fix "constexpr" and "override" keywords as well?

@eranif
Owner
eranif commented Sep 27, 2016

override was fixed in commit d311245 and f1ea963 I was not aware of constexpr not working ...
Will check this as well.

@yunkot
yunkot commented Sep 27, 2016

Thanks, regarding "constexpr" - variables do seem to be working now in latest weekly build, but functions are still not colored - please see my earlier comment with constexpr "sum" function example.

@yunkot
yunkot commented Sep 28, 2016 edited

I have installed weekly build on Windows dated Sep 27, 2016, and coloring seem to be different.

// MyNum appears as white
#define MyNum 25 

enum class MyEnum : uint8_t
{
  One, // "One" and "Two" now appear white
  Two
};

void test() // "test" appears white
{
}

Above, all aforementioned symbols now appear white, as identifiers. Previously enum constants and defines were green, while function names were blue. Is this supposed to be like that?

Edit: in some declarations, some function names may occasionally get colored in blue, but rest of them appear in white color, so I guess it could be a bug of some sort. Should I report this separately (could be a related regression)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment