Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[C++] Concept syntax not highlighted correctly

Open friedkeenan opened this issue 5 years ago • 2 comments

The new C++20 feature of concepts is not supported by the syntax highlighter. With the syntax shown below the syntax highlighter becomes very confused when used with classes, and with functions it just doesn't highlight everything correctly. With other ways of using concepts (such as template<std::integral T>), the issue is less severe.

  • Sublime Version: 3211 (also tested with package files as of 4b24b22994df74b2902ad2c2a58813d43f023423)
  • OS Version: x86_64 Linux 5.4.64-1-MANJARO
template<typename T> requires std::integral<T>
class Test {
    public:
        T value;
};

template<typename T> requires std::integral<T>
void test(T value) {
    /* ... */
}

friedkeenan avatar Sep 15 '20 14:09 friedkeenan

There's also the concept keyword now. Unfortunately, adding some contexts to parse concept Foo = ... at top-level scope doesn't work, as some libraries use a macro for the concept keyword: https://github.com/boostorg/asio/blob/c77f3b603bf2cd180945184a664c6a05d3bebd3b/include/boost/asio/execution/executor.hpp#L143

So it's going to be fun parsing concepts.

rwols avatar Aug 16 '21 09:08 rwols

I can also imagine libraries having a macro for requires to support older C++ version, creating something like

#if CPP_VERSION >= 20
#define REQUIRES(expr) requires expr
#else
#define REQUIRES(expr) // empty
#endif

template <typename T> REQUIRES(std::integral<T>)
void test(T value) {
    /* ... */
}

rwols avatar Aug 16 '21 09:08 rwols