diff --git a/autotests/folding/example.rmd.fold b/autotests/folding/example.rmd.fold --- a/autotests/folding/example.rmd.fold +++ b/autotests/folding/example.rmd.fold @@ -1,7 +1,7 @@ --- -title: "test" -author: "me" -date: "07.10.2014" +title: "test" +author: "me" +date: "07.10.2014" output: html_document --- diff --git a/autotests/folding/folding.cpp.fold b/autotests/folding/folding.cpp.fold --- a/autotests/folding/folding.cpp.fold +++ b/autotests/folding/folding.cpp.fold @@ -1,15 +1,15 @@ -/** +/** * multi-line comment - */ + */ -/* comment */ -{ { } { -//BEGIN -} -//END -} +/* comment */ +{ { } { +//BEGIN +} +//END +} -#if 0 -#elif 1 -#else -#endif +#if 0 +#elif 1#elif 1 +#else#else +#endif diff --git a/autotests/folding/highlight.cpp.fold b/autotests/folding/highlight.cpp.fold --- a/autotests/folding/highlight.cpp.fold +++ b/autotests/folding/highlight.cpp.fold @@ -3,60 +3,100 @@ #include #include #include "assert.h" -#include "assert.hpp" +#include "assert.hpp" // abc #include "path/assert.hpp" +#include "assert.h"a +#include "assert.h" a +#include a +#include a +#include FOO() error +#include_next a +#include_next /* a + */ b +#include PATH_IN_MACRO #include PATH_IN_MACRO() +#include PATH_IN_MACRO(a, b) #define SOME_VAR 1 -#ifdef SOME_VAR +#ifdef SOME_VAR #define MULTILINE_MACRO one \ two \ three # define MULTILINE_MACRO_TEXT \ - /* NOTE The contents of macro is too green :D */ \ + /* NOTE The contents of macro is too green :D */ \ char const s[] = "a\\b" \ "c\nd" +# define VARIADIC(a, ...) \ + f(a##a) \ + f(__VA_ARGS__) \ + f(#__VA_ARGS__) \ + f(__VA_ARGS__) \ + f(0 __VA_OPT__(,) __VA_ARGS__) \ + x __VA_OPT__(= { __VA_ARGS__ }) + +# define MACRO() BAD \ ESCAPED + # error dds # warning dds # line 2 "file.cpp" # define A(x, y) x##y x#y // OK(L, a) -> L"a" # define OK(x, y) x###y # define BAD(x, y) x####y +# define A /* multi line +with comment */ expr +# define A /* multi line +with comment */ +23 +#else // xelse // x +#42 // gcc extension = #line 42 + +// error +#wrong +# wrong +#endif x +#if DS() +#else xelse x +#else /* */xelse /* */x +#else /* xelse /* x +y */ z +#endif static int g_global; template class = std::is_pointer> struct class1 : private std::vector, public U -{ +{ class1() try : _member1(xxx) - {} + {} catch(...) - {} + {} + + class1(class1&&) = default; ~class1() - {} - - void foo() { return; } - void foo() const { return; } - void foo() noexcept { return; } - void foo() const noexcept { return; } - virtual void foo() const noexcept { return; } - static void foo() { return; } + {} + + void foo() { return; } + void foo() const { return; } + void foo() noexcept { return; } + void foo() const noexcept { return; } + virtual void foo() const noexcept { return; } + static void foo() { return; } constexpr static void foo() const noexcept(noexcept(std::is_pointer::value)) override - { - xxx::template ttt::type {}; + { + xxx::template ttt::type {}; xxx.template get(); xxx.std::rdbuf(); auto x = C<'a'> + y; - } + } int operator->*(T (C::*m)(int)); operator value_t (); @@ -72,54 +112,165 @@ value_type m_member3; static int s_static; -}; + static constexpr int s_static; + static inline int s_static; + static inline constexpr int s_static; +}; constexpr struct : xyz -{ +{ using xyz::xyz; using xyz::operator=; int a : 1; int b : 7; -} x {}; +} x {}; template using is_pointer = std::is_pointer::type; template constexpr auto is_pointer_v = std::is_pointer::value; uint64_t namespaces() -{ +{ std::vector; boost::vector; detail::vector; details::vector; aux::vector; internals::vector; other::vector; -} +} + +#if 1 + double foo(const A); +#else // else#else // else + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#else // else#else // else + double foo(const A); +#endif // end + +#if 1 + double foo(const A); +#elif 1#elif 1 + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif 1#elif 1 + double foo(const A); +#elif 0#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif a#elif a + double foo(const A); +#elif 0elif 0 + double foo(const A); +#elif a#elif a + double foo(const A); +#else // elseelse // else + double foo(const A); +#endif // end + +#if 0 // blah blah + double foo(const A); +#elif 1 // blah blah#elif 1 // blah blah + double foo(const A); +#else // else#else // else + double foo(const A); +#endif // end + +#if 0 || a + double foo(const A); +#else // elseelse // else + double foo(const A); +#endif // end + +#if 1 || a + double foo(const A); +#else // else#else // else + double foo(const A); +#endif // end + +#if 0 && a + double foo(const A); +#else // elseelse // else + double foo(const A); +#endif // end -#if 1 +#if 1 && a double foo(const A); -#else +#else // elseelse // else double foo(const A); -#endif +#endif // end -#if 0 +#if a double foo(const A); -#else +#elif 0elif 0 double foo(const A); -#endif +#endif // end + +#if a + double foo(const A); +#elif 1elif 1 + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif aelif a + double foo(const A); +#endif // end int bar(void*p, void * pp) -{ -# if 0 +{ +# if 0 double foo(); -# else +# else // else# else // else double foo(); -# endif -} +# endif // end +} + +#if abc 0 + double foo(); +#endif // end + +#if xxx + double foo(); +#elseelse + double foo(); +#endif // end + +#if xxx + double foo(); +#elif xxx // elseifelif xxx // elseif + double foo(); +#elif xxx // elseifelif xxx // elseif + double foo(); +#endif // end + +// error +# +#d +# d +#if +#elifelif +#endif +#ifndef +#endif +#ifdef 0 +#endif // end static uint64_t intWithSuffix = 42ull; static long intWithSuffixAndPrefix = 0b0101L; @@ -130,7 +281,7 @@ static char binNum = 0b0101010; static int64_t intWithSuffix = -42LL; -static long intWithSuffixAndPrefix = -0b0101L; // BUG +static long intWithSuffixAndPrefix = -0b0101L; static int octNum = -07232; static int invalidOctNum = -09231; static int64_t hexNum = -0xDEADBEEF42; @@ -145,6 +296,9 @@ static uint64_t invalidHexNumWithSep = 0xGLD'FKG; static char binNumWithSep = 0b0'1010'10; +static uint64_t invalidSep = 42'ull; +static uint64_t invalidSep = 42'; + static double d1 = 42.; static double d2 = .42; static double d2a = -0.49; @@ -154,30 +308,66 @@ static double d5 = 32.e+12; static double invalidD1 = 32.e+a12; static float floatQualifier = 23.123f; -// TODO c++17 +// Hexadecimal floating point (c++17) static double d6 = 0x1ffp10; static double d7 = 0X0p-1; static double d8 = 0x1.p0; -static double d9 = 0xf.p-1; +static double d9 = 0xf.p-1L; static double d10 = 0x0.123p-1; static double d11 = 0xa.bp10l; static double invalidD2 = 0x0.123p-a; static float floatQualifier = 0xf.p-1f; +60min; // c++17 +23._f +23._fd +2.3_f +2.3_fd +2._f +2._fd +2e4_f +2e4_fd + +// error +23.fd +2e_fd +2e +1.y +1.0_E+2.0 +1.0_E +2.0 // ok +1_p+2 +1_p +2 // ok +4s.count() +4s. count() +4s .count() // ok + static bool yes = true; static bool no = false; - -static const char c1 = 'c'; -static const char c1a = u8'c'; // TODO c++17 -static const char16_t c1b = u'c'; -static const char32_t c1c = U'c'; -static const wchar_t c1d = L'c'; +// *char* +static const char c1 = 'c'; +static const char c1a = u8'c'; // utf-8 char (c++17) +static const char16_t c1b = u'c'; +static const char32_t c1c = U'c'; +static const wchar_t c1d = L'c'; static const char c2 = '\n'; static const char c2a = '\120'; // octal static const char c2b = '\x1f'; // hex static const char c2c = '\''; static const char c2d = '\\'; +static const wchar_t c2e = L'\x1ff'; // hex +static const wchar_t c2e = U'\x1fffffff'; // hex +// error +'\x123'; +'\u1234'; +'\U12345678'; +U'\u12345'; +u'\u123'; +U'\U1234567'; +U'\U123456789'; +U'\x123456789'; + +// string static const char* c3 = "string"; static const char* c4 = "\"string\n\t\012\x12\""; static const char* c5 = "multiline \ @@ -195,18 +385,24 @@ static const char* rawString2 = R"ab(string\nstring)ab"; static const char* rawString3 = R"ab(string string)ab"; +" %d %df fd" U"ds %d" R"(a%d)"; + "\x123xsk"; + u"\x123xsk"; +// error +u8"\x123xsk"; // UDL (c++11) -operator""_a(const char*); // BUG operator not colorized -operator ""_a(const char*); // BUG colorized or -operator "" _a(const char*); // BUG or not colorized +operator""_a(const char*); +operator ""_a(const char*); +operator "" _a(const char*); +// invalid suffix operator "" a(const char*); -operator ""a(const char*); // BUG -operator""a(const char*); // BUG +operator ""a(const char*); +operator""a(const char*); -"string"_s; // BUG colorized or -"string"s; // BUG or not colorized +"string"_s; // user +"string"s; // standard "string"_s-b; // -b is not part of the string // Macro @@ -228,34 +424,38 @@ [[using CC: opt(1), debug]] // c++17 [[using CC: CC::opt(1)]] // c++17 +[[gnu::assume_aligned(3'2l,2)]] void* f(); +[[using gnu: assume_aligned(3)]] +[[clang::assume_aligned(3)]] + void f([[maybe_unused]] int val) -{ +{ [[maybe_unused]] int x; - switch (x = foo(); x) { + switch (x = foo(); x) { case 1: [[fallthrough]]; case XXX: case Class::foo(): [[fallthrough]]; default: ; - } + } // c++17: fold expression (args + ... + (1 * 2)); (v.push_back(args), ...); [[omp::parallel]] for (auto&& x : v) x; - for (auto&& [first,second] : mymap) { - } + for (auto&& [first,second] : mymap) { + } auto [x, y] = foo(); - [x = 1, =y](){}; + [x = 1, =y](){}; decltype((auto)) x = foo(); -} +} auto f() -> decltype(foo()); @@ -265,30 +465,28 @@ goto label; -//BEGIN region +//BEGIN region // TODO comment FIXME comment ### comment BUG comment -//END region - -#wrong +//END region // \brief blah blah /// \brief blah blah -/** +/** * Doxygen * @param p1 text * \brief bold text - * \dot + * \dot * a -> b - * \enddot + * \enddot * - * \verbatim + * \verbatim * - * \endverbatim + * \endverbatim * text - */ + */ -#endif +#endif // Some GNU macros, cross-referenced from gcc.xml to isocpp.xml __GCC_ATOMIC_CHAR16_T_LOCK_FREE diff --git a/autotests/folding/highlight.lex.fold b/autotests/folding/highlight.lex.fold --- a/autotests/folding/highlight.lex.fold +++ b/autotests/folding/highlight.lex.fold @@ -4,7 +4,7 @@ %option yyclass="KateTester" %option yylineno - /* This is a C(++) comment */ + /* This is a C(++) comment */ /* This one is a lex comment ! */ @@ -20,30 +20,30 @@ %%%% - /* Comment *shall be indented here* */ + /* Comment *shall be indented here* */ [ \t\n\r]+ - /* Note: there is a bad } just here vvv */ + /* Note: there is a bad } just here vvv */ \/\*([^\*]|\*[^/])*\*\/ { foo(a, b, c); } } - /* A start condition scope... */ + /* A start condition scope... */ { "a" { - /* C mode ! */ + /* C mode ! */ return 0; } "b" %{ - /* C mode, too ! */ + /* C mode, too ! */ return 0; %} "c" return 0; // C++ comment } - /* Big rule */ + /* Big rule */ \"([^"\\]|\\.)*\" { yylval.string_val = new char[strlen(yytext) + 1]; @@ -67,16 +67,16 @@ } - /* Dot (match all) */ + /* Dot (match all) */ . {return yylval.int_val = yytext[0];} %%%% // Here is pure C(++) #include int main(void) -{ +{ std::cout << "Hello, World\n"; return 0; -} +} diff --git a/autotests/folding/highlight.y.fold b/autotests/folding/highlight.y.fold --- a/autotests/folding/highlight.y.fold +++ b/autotests/folding/highlight.y.fold @@ -87,7 +87,7 @@ #include int main(void) -{ +{ puts("Hello, World!"); return 0; -} +} diff --git a/autotests/folding/preprocessor-bug363280.cpp.fold b/autotests/folding/preprocessor-bug363280.cpp.fold --- a/autotests/folding/preprocessor-bug363280.cpp.fold +++ b/autotests/folding/preprocessor-bug363280.cpp.fold @@ -1,8 +1,8 @@ -#if 1 +#if 1 int x; // variable shall not be grey -#endif -#if defined (A) +#endif +#if defined (A) int y; // variable shall not be grey -#elif defined (B) +#elif defined (B)elif defined (B) int z; // variable shall not be grey -#endif +#endif diff --git a/autotests/html/folding.cpp.html b/autotests/html/folding.cpp.html --- a/autotests/html/folding.cpp.html +++ b/autotests/html/folding.cpp.html @@ -16,7 +16,7 @@ } #if 0 -#elif 1 +#elif 1 #else #endif diff --git a/autotests/html/highlight.cpp.html b/autotests/html/highlight.cpp.html --- a/autotests/html/highlight.cpp.html +++ b/autotests/html/highlight.cpp.html @@ -9,29 +9,67 @@ #include <cassert> #include <assert.h> #include "assert.h" -#include "assert.hpp" +#include "assert.hpp" // abc #include "path/assert.hpp" +#include "assert.h"a +#include "assert.h" a +#include <cassert>a +#include <cassert> a +#include FOO() error +#include_next <cassert> a +#include_next <cassert> /* a + */ b +#include PATH_IN_MACRO #include PATH_IN_MACRO() +#include PATH_IN_MACRO(a, b) -#define SOME_VAR 1 +#define SOME_VAR 1 #ifdef SOME_VAR #define MULTILINE_MACRO one \ two \ three # define MULTILINE_MACRO_TEXT \ - /* NOTE The contents of macro is too green :D */ \ - char const s[] = "a\\b" \ - "c\nd" + /* NOTE The contents of macro is too green :D */ \ + char const s[] = "a\\b" \ + "c\nd" + +# define VARIADIC(a, ...) \ + f(a##a) \ + f(__VA_ARGS__) \ + f(#__VA_ARGS__) \ + f(__VA_ARGS__) \ + f(0 __VA_OPT__(,) __VA_ARGS__) \ + x __VA_OPT__(= { __VA_ARGS__ }) + +# define MACRO() BAD \ ESCAPED # error dds # warning dds # line 2 "file.cpp" -# define A(x, y) x##y x#y +# define A(x, y) x##y x#y // OK(L, a) -> L"a" -# define OK(x, y) x###y -# define BAD(x, y) x####y +# define OK(x, y) x###y +# define BAD(x, y) x####y +# define A /* multi line +with comment */ expr +# define A /* multi line +with comment */ +23 +#else // x +#42 // gcc extension = #line 42 + +// error +#wrong +# wrong +#endif x +#if DS() +#else x +#else /* */x +#else /* x +y */ z +#endif static int g_global; @@ -46,6 +84,8 @@ catch(...) {} + class1(class1&&) = default; + ~class1() {} @@ -78,6 +118,9 @@ value_type m_member3; static int s_static; + static constexpr int s_static; + static inline int s_static; + static inline constexpr int s_static; }; constexpr struct : xyz @@ -108,82 +151,229 @@ #if 1 double foo(const A); -#else +#else // else double foo(const A); -#endif +#endif // end #if 0 double foo(const A); -#else +#else // else double foo(const A); -#endif +#endif // end + +#if 1 + double foo(const A); +#elif 1 + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif 1 + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif a + double foo(const A); +#elif 0 + double foo(const A); +#elif a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 // blah blah + double foo(const A); +#elif 1 // blah blah + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 || a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 1 || a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 && a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 1 && a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif 1 + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif a + double foo(const A); +#endif // end int bar(void*p, void * pp) { # if 0 double foo(); -# else +# else // else double foo(); -# endif +# endif // end } -static uint64_t intWithSuffix = 42ull; -static long intWithSuffixAndPrefix = 0b0101L; +#if abc 0 + double foo(); +#endif // end + +#if xxx + double foo(); +#else + double foo(); +#endif // end + +#if xxx + double foo(); +#elif xxx // elseif + double foo(); +#elif xxx // elseif + double foo(); +#endif // end + +// error +# +#d +# d +#if +#elif +#endif +#ifndef +#endif +#ifdef 0 +#endif // end + +static uint64_t intWithSuffix = 42ull; +static long intWithSuffixAndPrefix = 0b0101L; static int octNum = 07232; static int invalidOctNum = 09231; static uint64_t hexNum = 0xDEADBEEF42; static uint64_t invalidHexNum = 0xGLDFKG; static char binNum = 0b0101010; -static int64_t intWithSuffix = -42LL; -static long intWithSuffixAndPrefix = -0b0101L; // BUG -static int octNum = -07232; -static int invalidOctNum = -09231; -static int64_t hexNum = -0xDEADBEEF42; -static int64_t invalidHexNum = -0xGLDFKG; -static char binNum = -0b0101010; +static int64_t intWithSuffix = -42LL; +static long intWithSuffixAndPrefix = -0b0101L; +static int octNum = -07232; +static int invalidOctNum = -09231; +static int64_t hexNum = -0xDEADBEEF42; +static int64_t invalidHexNum = -0xGLDFKG; +static char binNum = -0b0101010; -static uint64_t intWithSuffixWithSep = 4'2ull; -static long intWithSuffixAndPrefixWithSep = 0b0'10'1L; +static uint64_t intWithSuffixWithSep = 4'2ull; +static long intWithSuffixAndPrefixWithSep = 0b0'10'1L; static int octNumWithSep = 07'232; -static int invalidOctNumWithSep = 09'23'1; +static int invalidOctNumWithSep = 09'23'1; static uint64_t hexNumWithSep = 0xD'EAD'BE'EF'42; -static uint64_t invalidHexNumWithSep = 0xGLD'FKG; +static uint64_t invalidHexNumWithSep = 0xGLD'FKG; static char binNumWithSep = 0b0'1010'10; +static uint64_t invalidSep = 42'ull; +static uint64_t invalidSep = 42'; + static double d1 = 42.; static double d2 = .42; -static double d2a = -0.49; -static double d2b = -0.09; +static double d2a = -0.49; +static double d2b = -0.09; static double d3 = 42.3e1; static double d4 = .2e-12; static double d5 = 32.e+12; -static double invalidD1 = 32.e+a12; -static float floatQualifier = 23.123f; -// TODO c++17 -static double d6 = 0x1ffp10; -static double d7 = 0X0p-1; -static double d8 = 0x1.p0; -static double d9 = 0xf.p-1; -static double d10 = 0x0.123p-1; -static double d11 = 0xa.bp10l; -static double invalidD2 = 0x0.123p-a; -static float floatQualifier = 0xf.p-1f; +static double invalidD1 = 32.e+a12; +static float floatQualifier = 23.123f; +// Hexadecimal floating point (c++17) +static double d6 = 0x1ffp10; +static double d7 = 0X0p-1; +static double d8 = 0x1.p0; +static double d9 = 0xf.p-1L; +static double d10 = 0x0.123p-1; +static double d11 = 0xa.bp10l; +static double invalidD2 = 0x0.123p-a; +static float floatQualifier = 0xf.p-1f; + +60min; // c++17 +23._f +23._fd +2.3_f +2.3_fd +2._f +2._fd +2e4_f +2e4_fd + +// error +23.fd +2e_fd +2e +1.y +1.0_E+2.0 +1.0_E +2.0 // ok +1_p+2 +1_p +2 // ok +4s.count() +4s. count() +4s .count() // ok static bool yes = true; static bool no = false; - -static const char c1 = 'c'; -static const char c1a = u8'c'; // TODO c++17 -static const char16_t c1b = u'c'; -static const char32_t c1c = U'c'; -static const wchar_t c1d = L'c'; +// *char* +static const char c1 = 'c'; +static const char c1a = u8'c'; // utf-8 char (c++17) +static const char16_t c1b = u'c'; +static const char32_t c1c = U'c'; +static const wchar_t c1d = L'c'; static const char c2 = '\n'; static const char c2a = '\120'; // octal static const char c2b = '\x1f'; // hex static const char c2c = '\''; static const char c2d = '\\'; +static const wchar_t c2e = L'\x1ff'; // hex +static const wchar_t c2e = U'\x1fffffff'; // hex +// error +'\x123'; +'\u1234'; +'\U12345678'; +U'\u12345'; +u'\u123'; +U'\U1234567'; +U'\U123456789'; +U'\x123456789'; + +// string static const char* c3 = "string"; static const char* c4 = "\"string\n\t\012\x12\""; static const char* c5 = "multiline \ @@ -201,19 +391,25 @@ static const char* rawString2 = R"ab(string\nstring)ab"; static const char* rawString3 = R"ab(string string)ab"; +" %d %df fd" U"ds %d" R"(a%d)"; + "\x123xsk"; + u"\x123xsk"; +// error +u8"\x123xsk"; // UDL (c++11) -operator""_a(const char*); // BUG operator not colorized -operator ""_a(const char*); // BUG colorized or -operator "" _a(const char*); // BUG or not colorized -operator "" a(const char*); -operator ""a(const char*); // BUG -operator""a(const char*); // BUG +operator""_a(const char*); +operator ""_a(const char*); +operator "" _a(const char*); +// invalid suffix +operator "" a(const char*); +operator ""a(const char*); +operator""a(const char*); -"string"_s; // BUG colorized or -"string"s; // BUG or not colorized -"string"_s-b; // -b is not part of the string +"string"_s; // user +"string"s; // standard +"string"_s-b; // -b is not part of the string // Macro @@ -230,9 +426,13 @@ [[deprecated("because")]] void foo(); void foo([[carries_dependency]] int); -[[opt(1), debug]] -[[using CC: opt(1), debug]] // c++17 -[[using CC: CC::opt(1)]] // c++17 +[[opt(1), debug]] +[[using CC: opt(1), debug]] // c++17 +[[using CC: CC::opt(1)]] // c++17 + +[[gnu::assume_aligned(3'2l,2)]] void* f(); +[[using gnu: assume_aligned(3)]] +[[clang::assume_aligned(3)]] void f([[maybe_unused]] int val) { @@ -251,7 +451,7 @@ (args + ... + (1 * 2)); (v.push_back(args), ...); - [[omp::parallel]] for (auto&& x : v) + [[omp::parallel]] for (auto&& x : v) x; for (auto&& [first,second] : mymap) { } @@ -275,8 +475,6 @@ // TODO comment FIXME comment ### comment BUG comment //END region -#wrong - // \brief blah blah /// \brief blah blah diff --git a/autotests/input/highlight.cpp b/autotests/input/highlight.cpp --- a/autotests/input/highlight.cpp +++ b/autotests/input/highlight.cpp @@ -3,9 +3,19 @@ #include #include #include "assert.h" -#include "assert.hpp" +#include "assert.hpp" // abc #include "path/assert.hpp" +#include "assert.h"a +#include "assert.h" a +#include a +#include a +#include FOO() error +#include_next a +#include_next /* a + */ b +#include PATH_IN_MACRO #include PATH_IN_MACRO() +#include PATH_IN_MACRO(a, b) #define SOME_VAR 1 #ifdef SOME_VAR @@ -19,13 +29,41 @@ char const s[] = "a\\b" \ "c\nd" +# define VARIADIC(a, ...) \ + f(a##a) \ + f(__VA_ARGS__) \ + f(#__VA_ARGS__) \ + f(__VA_ARGS__) \ + f(0 __VA_OPT__(,) __VA_ARGS__) \ + x __VA_OPT__(= { __VA_ARGS__ }) + +# define MACRO() BAD \ ESCAPED + # error dds # warning dds # line 2 "file.cpp" # define A(x, y) x##y x#y // OK(L, a) -> L"a" # define OK(x, y) x###y # define BAD(x, y) x####y +# define A /* multi line +with comment */ expr +# define A /* multi line +with comment */ +23 +#else // x +#42 // gcc extension = #line 42 + +// error +#wrong +# wrong +#endif x +#if DS() +#else x +#else /* */x +#else /* x +y */ z +#endif static int g_global; @@ -40,6 +78,8 @@ catch(...) {} + class1(class1&&) = default; + ~class1() {} @@ -72,6 +112,9 @@ value_type m_member3; static int s_static; + static constexpr int s_static; + static inline int s_static; + static inline constexpr int s_static; }; constexpr struct : xyz @@ -102,25 +145,133 @@ #if 1 double foo(const A); -#else +#else // else double foo(const A); -#endif +#endif // end #if 0 double foo(const A); -#else +#else // else double foo(const A); -#endif +#endif // end + +#if 1 + double foo(const A); +#elif 1 + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif 1 + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if 0 + double foo(const A); +#elif a + double foo(const A); +#elif 0 + double foo(const A); +#elif a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 // blah blah + double foo(const A); +#elif 1 // blah blah + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 || a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 1 || a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 0 && a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if 1 && a + double foo(const A); +#else // else + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif 0 + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif 1 + double foo(const A); +#endif // end + +#if a + double foo(const A); +#elif a + double foo(const A); +#endif // end int bar(void*p, void * pp) { # if 0 double foo(); -# else +# else // else double foo(); -# endif +# endif // end } +#if abc 0 + double foo(); +#endif // end + +#if xxx + double foo(); +#else + double foo(); +#endif // end + +#if xxx + double foo(); +#elif xxx // elseif + double foo(); +#elif xxx // elseif + double foo(); +#endif // end + +// error +# +#d +# d +#if +#elif +#endif +#ifndef +#endif +#ifdef 0 +#endif // end + static uint64_t intWithSuffix = 42ull; static long intWithSuffixAndPrefix = 0b0101L; static int octNum = 07232; @@ -130,7 +281,7 @@ static char binNum = 0b0101010; static int64_t intWithSuffix = -42LL; -static long intWithSuffixAndPrefix = -0b0101L; // BUG +static long intWithSuffixAndPrefix = -0b0101L; static int octNum = -07232; static int invalidOctNum = -09231; static int64_t hexNum = -0xDEADBEEF42; @@ -145,6 +296,9 @@ static uint64_t invalidHexNumWithSep = 0xGLD'FKG; static char binNumWithSep = 0b0'1010'10; +static uint64_t invalidSep = 42'ull; +static uint64_t invalidSep = 42'; + static double d1 = 42.; static double d2 = .42; static double d2a = -0.49; @@ -154,30 +308,66 @@ static double d5 = 32.e+12; static double invalidD1 = 32.e+a12; static float floatQualifier = 23.123f; -// TODO c++17 +// Hexadecimal floating point (c++17) static double d6 = 0x1ffp10; static double d7 = 0X0p-1; static double d8 = 0x1.p0; -static double d9 = 0xf.p-1; +static double d9 = 0xf.p-1L; static double d10 = 0x0.123p-1; static double d11 = 0xa.bp10l; static double invalidD2 = 0x0.123p-a; static float floatQualifier = 0xf.p-1f; +60min; // c++17 +23._f +23._fd +2.3_f +2.3_fd +2._f +2._fd +2e4_f +2e4_fd + +// error +23.fd +2e_fd +2e +1.y +1.0_E+2.0 +1.0_E +2.0 // ok +1_p+2 +1_p +2 // ok +4s.count() +4s. count() +4s .count() // ok + static bool yes = true; static bool no = false; - -static const char c1 = 'c'; -static const char c1a = u8'c'; // TODO c++17 -static const char16_t c1b = u'c'; -static const char32_t c1c = U'c'; -static const wchar_t c1d = L'c'; +// *char* +static const char c1 = 'c'; +static const char c1a = u8'c'; // utf-8 char (c++17) +static const char16_t c1b = u'c'; +static const char32_t c1c = U'c'; +static const wchar_t c1d = L'c'; static const char c2 = '\n'; static const char c2a = '\120'; // octal static const char c2b = '\x1f'; // hex static const char c2c = '\''; static const char c2d = '\\'; +static const wchar_t c2e = L'\x1ff'; // hex +static const wchar_t c2e = U'\x1fffffff'; // hex +// error +'\x123'; +'\u1234'; +'\U12345678'; +U'\u12345'; +u'\u123'; +U'\U1234567'; +U'\U123456789'; +U'\x123456789'; + +// string static const char* c3 = "string"; static const char* c4 = "\"string\n\t\012\x12\""; static const char* c5 = "multiline \ @@ -195,18 +385,24 @@ static const char* rawString2 = R"ab(string\nstring)ab"; static const char* rawString3 = R"ab(string string)ab"; +" %d %df fd" U"ds %d" R"(a%d)"; + "\x123xsk"; + u"\x123xsk"; +// error +u8"\x123xsk"; // UDL (c++11) -operator""_a(const char*); // BUG operator not colorized -operator ""_a(const char*); // BUG colorized or -operator "" _a(const char*); // BUG or not colorized +operator""_a(const char*); +operator ""_a(const char*); +operator "" _a(const char*); +// invalid suffix operator "" a(const char*); -operator ""a(const char*); // BUG -operator""a(const char*); // BUG +operator ""a(const char*); +operator""a(const char*); -"string"_s; // BUG colorized or -"string"s; // BUG or not colorized +"string"_s; // user +"string"s; // standard "string"_s-b; // -b is not part of the string // Macro @@ -228,6 +424,10 @@ [[using CC: opt(1), debug]] // c++17 [[using CC: CC::opt(1)]] // c++17 +[[gnu::assume_aligned(3'2l,2)]] void* f(); +[[using gnu: assume_aligned(3)]] +[[clang::assume_aligned(3)]] + void f([[maybe_unused]] int val) { [[maybe_unused]] int x; @@ -269,8 +469,6 @@ // TODO comment FIXME comment ### comment BUG comment //END region -#wrong - // \brief blah blah /// \brief blah blah diff --git a/autotests/reference/folding.cpp.ref b/autotests/reference/folding.cpp.ref --- a/autotests/reference/folding.cpp.ref +++ b/autotests/reference/folding.cpp.ref @@ -10,6 +10,6 @@ }

#if 0
-#elif 1
+#elif 1
#else
#endif
diff --git a/autotests/reference/highlight.cpp.ref b/autotests/reference/highlight.cpp.ref --- a/autotests/reference/highlight.cpp.ref +++ b/autotests/reference/highlight.cpp.ref @@ -3,29 +3,67 @@ #include
#include
#include "assert.h"
-#include "assert.hpp"
+#include "assert.hpp" // abc
#include "path/assert.hpp"
+#include "assert.h"a
+#include "assert.h" a
+#include a
+#include a
+#include FOO() error
+#include_next a
+#include_next /* a
+ */ b
+#include PATH_IN_MACRO
#include PATH_IN_MACRO()
+#include PATH_IN_MACRO(a, b)

-#define SOME_VAR 1
+#define SOME_VAR 1
#ifdef SOME_VAR

#define MULTILINE_MACRO one \
two \
three

# define MULTILINE_MACRO_TEXT \
- /* NOTE The contents of macro is too green :D */ \
- char const s[] = "a\\b" \
- "c\nd"
+ /* NOTE The contents of macro is too green :D */ \
+ char const s[] = "a\\b" \
+ "c\nd"
+
+# define VARIADIC(a, ...) \
+ f(a##a) \
+ f(__VA_ARGS__) \
+ f(#__VA_ARGS__) \
+ f(__VA_ARGS__) \
+ f(0 __VA_OPT__(,) __VA_ARGS__) \
+ x __VA_OPT__(= { __VA_ARGS__ })
+
+# define MACRO() BAD \ ESCAPED

# error dds
# warning dds
# line 2 "file.cpp"
-# define A(x, y) x##y x#y
+# define A(x, y) x##y x#y
// OK(L, a) -> L"a"
-# define OK(x, y) x###y
-# define BAD(x, y) x####y
+# define OK(x, y) x###y
+# define BAD(x, y) x####y
+# define A /* multi line
+with comment */ expr
+# define A /* multi line
+with comment */
+23
+#else // x
+#42 // gcc extension = #line 42
+
+// error
+#wrong
+# wrong
+#endif x
+#if DS()
+#else x
+#else /* */x
+#else /* x
+y */ z
+#endif

static int g_global;

@@ -40,6 +78,8 @@ catch(...)
{}

+ class1(class1&&) = default;
+
~class1()
{}

@@ -72,6 +112,9 @@ value_type m_member3;

static int s_static;
+ static constexpr int s_static;
+ static inline int s_static;
+ static inline constexpr int s_static;
};

constexpr struct : xyz
@@ -102,82 +145,229 @@
#if 1
double foo(const A);
-#else
+#else // else
double foo(const A);
-#endif
+#endif // end

#if 0
double foo(const A);
-#else
+#else // else
double foo(const A);
-#endif
+#endif // end
+
+#if 1
+ double foo(const A);
+#elif 1
+ double foo(const A);
+#elif 0
+ double foo(const A);
+#endif // end
+
+#if 0
+ double foo(const A);
+#elif 1
+ double foo(const A);
+#elif 0
+ double foo(const A);
+#endif // end
+
+#if 0
+ double foo(const A);
+#elif a
+ double foo(const A);
+#elif 0
+ double foo(const A);
+#elif a
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if 0 // blah blah
+ double foo(const A);
+#elif 1 // blah blah
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if 0 || a
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if 1 || a
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if 0 && a
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if 1 && a
+ double foo(const A);
+#else // else
+ double foo(const A);
+#endif // end
+
+#if a
+ double foo(const A);
+#elif 0
+ double foo(const A);
+#endif // end
+
+#if a
+ double foo(const A);
+#elif 1
+ double foo(const A);
+#endif // end
+
+#if a
+ double foo(const A);
+#elif a
+ double foo(const A);
+#endif // end

int bar(void*p, void * pp)
{
# if 0
double foo();
-# else
+# else // else
double foo();
-# endif
+# endif // end
}

-static uint64_t intWithSuffix = 42ull;
-static long intWithSuffixAndPrefix = 0b0101L;
+#if abc 0
+ double foo();
+#endif // end
+
+#if xxx
+ double foo();
+#else
+ double foo();
+#endif // end
+
+#if xxx
+ double foo();
+#elif xxx // elseif
+ double foo();
+#elif xxx // elseif
+ double foo();
+#endif // end
+
+// error
+#
+#d
+# d
+#if
+#elif
+#endif
+#ifndef
+#endif
+#ifdef 0
+#endif // end
+
+static uint64_t intWithSuffix = 42ull;
+static long intWithSuffixAndPrefix = 0b0101L;
static int octNum = 07232;
static int invalidOctNum = 09231;
static uint64_t hexNum = 0xDEADBEEF42;
static uint64_t invalidHexNum = 0xGLDFKG;
static char binNum = 0b0101010;

-static int64_t intWithSuffix = -42LL;
-static long intWithSuffixAndPrefix = -0b0101L; // BUG
-static int octNum = -07232;
-static int invalidOctNum = -09231;
-static int64_t hexNum = -0xDEADBEEF42;
-static int64_t invalidHexNum = -0xGLDFKG;
-static char binNum = -0b0101010;
+static int64_t intWithSuffix = -42LL;
+static long intWithSuffixAndPrefix = -0b0101L;
+static int octNum = -07232;
+static int invalidOctNum = -09231;
+static int64_t hexNum = -0xDEADBEEF42;
+static int64_t invalidHexNum = -0xGLDFKG;
+static char binNum = -0b0101010;

-static uint64_t intWithSuffixWithSep = 4'2ull;
-static long intWithSuffixAndPrefixWithSep = 0b0'10'1L;
+static uint64_t intWithSuffixWithSep = 4'2ull;
+static long intWithSuffixAndPrefixWithSep = 0b0'10'1L;
static int octNumWithSep = 07'232;
-static int invalidOctNumWithSep = 09'23'1;
+static int invalidOctNumWithSep = 09'23'1;
static uint64_t hexNumWithSep = 0xD'EAD'BE'EF'42;
-static uint64_t invalidHexNumWithSep = 0xGLD'FKG;
+static uint64_t invalidHexNumWithSep = 0xGLD'FKG;
static char binNumWithSep = 0b0'1010'10;

+static uint64_t invalidSep = 42'ull;
+static uint64_t invalidSep = 42';
+
static double d1 = 42.;
static double d2 = .42;
-static double d2a = -0.49;
-static double d2b = -0.09;
+static double d2a = -0.49;
+static double d2b = -0.09;
static double d3 = 42.3e1;
static double d4 = .2e-12;
static double d5 = 32.e+12;
-static double invalidD1 = 32.e+a12;
-static float floatQualifier = 23.123f;
-// TODO c++17
-static double d6 = 0x1ffp10;
-static double d7 = 0X0p-1;
-static double d8 = 0x1.p0;
-static double d9 = 0xf.p-1;
-static double d10 = 0x0.123p-1;
-static double d11 = 0xa.bp10l;
-static double invalidD2 = 0x0.123p-a;
-static float floatQualifier = 0xf.p-1f;
+static double invalidD1 = 32.e+a12;
+static float floatQualifier = 23.123f;
+// Hexadecimal floating point (c++17)
+static double d6 = 0x1ffp10;
+static double d7 = 0X0p-1;
+static double d8 = 0x1.p0;
+static double d9 = 0xf.p-1L;
+static double d10 = 0x0.123p-1;
+static double d11 = 0xa.bp10l;
+static double invalidD2 = 0x0.123p-a;
+static float floatQualifier = 0xf.p-1f;
+
+60min; // c++17
+23._f
+23._fd
+2.3_f
+2.3_fd
+2._f
+2._fd
+2e4_f
+2e4_fd
+
+// error
+23.fd
+2e_fd
+2e
+1.y
+1.0_E+2.0
+1.0_E +2.0 // ok
+1_p+2
+1_p +2 // ok
+4s.count()
+4s. count()
+4s .count() // ok

static bool yes = true;
static bool no = false;

-
-static const char c1 = 'c';
-static const char c1a = u8'c'; // TODO c++17
-static const char16_t c1b = u'c';
-static const char32_t c1c = U'c';
-static const wchar_t c1d = L'c';
+// *char*
+static const char c1 = 'c';
+static const char c1a = u8'c'; // utf-8 char (c++17)
+static const char16_t c1b = u'c';
+static const char32_t c1c = U'c';
+static const wchar_t c1d = L'c';
static const char c2 = '\n';
static const char c2a = '\120'; // octal
static const char c2b = '\x1f'; // hex
static const char c2c = '\'';
static const char c2d = '\\';
+static const wchar_t c2e = L'\x1ff'; // hex
+static const wchar_t c2e = U'\x1fffffff'; // hex
+// error
+'\x123';
+'\u1234';
+'\U12345678';
+U'\u12345';
+u'\u123';
+U'\U1234567';
+U'\U123456789';
+U'\x123456789';
+
+// string
static const char* c3 = "string";
static const char* c4 = "\"string\n\t\012\x12\"";
static const char* c5 = "multiline \
@@ -195,19 +385,25 @@ static const char* rawString2 = R"ab(string\nstring)ab";
static const char* rawString3 = R"ab(string
string)ab";
+" %d %df fd" U"ds %d" R"(a%d)";
+ "\x123xsk";
+ u"\x123xsk";
+// error
+u8"\x123xsk";

// UDL (c++11)

-operator""_a(const char*); // BUG operator not colorized
-operator ""_a(const char*); // BUG colorized or
-operator "" _a(const char*); // BUG or not colorized
-operator "" a(const char*);
-operator ""a(const char*); // BUG
-operator""a(const char*); // BUG
+operator""_a(const char*);
+operator ""_a(const char*);
+operator "" _a(const char*);
+// invalid suffix
+operator "" a(const char*);
+operator ""a(const char*);
+operator""a(const char*);

-"string"_s; // BUG colorized or
-"string"s; // BUG or not colorized
-"string"_s-b; // -b is not part of the string
+"string"_s; // user
+"string"s; // standard
+"string"_s-b; // -b is not part of the string

// Macro

@@ -224,28 +420,32 @@ [[deprecated("because")]] void foo();
void foo([[carries_dependency]] int);

-[[opt(1), debug]]
-[[using CC: opt(1), debug]] // c++17
-[[using CC: CC::opt(1)]] // c++17
+[[opt(1), debug]]
+[[using CC: opt(1), debug]] // c++17
+[[using CC: CC::opt(1)]] // c++17

-void f([[maybe_unused]] int val)
+[[gnu::assume_aligned(3'2l,2)]] void* f();
+[[using gnu: assume_aligned(3)]]
+[[clang::assume_aligned(3)]]
+
+void f([[maybe_unused]] int val)
{
- [[maybe_unused]] int x;
+ [[maybe_unused]] int x;
switch (x = foo(); x) {
case 1:
- [[fallthrough]];
+ [[fallthrough]];
case XXX:
case Class::foo():
- [[fallthrough]];
+ [[fallthrough]];
default:
;
}

// c++17: fold expression
(args + ... + (1 * 2));
(v.push_back(args), ...);

- [[omp::parallel]] for (auto&& x : v)
+ [[omp::parallel]] for (auto&& x : v)
x;
for (auto&& [first,second] : mymap) {
}
@@ -269,8 +469,6 @@ // TODO comment FIXME comment ### comment BUG comment
//END region

-#wrong
-
// \brief blah blah
/// \brief blah blah

diff --git a/data/syntax/gcc.xml b/data/syntax/gcc.xml --- a/data/syntax/gcc.xml +++ b/data/syntax/gcc.xml @@ -13,7 +13,7 @@ --> __UINT_LEAST8_TYPE__ __USER_LABEL_PREFIX__ __USING_SJLJ_EXCEPTIONS__ - __VA_ARGS__ __VERSION__ __WCHAR_MAX__ __WCHAR_MIN__ @@ -532,12 +531,20 @@ - - + + + + + + + + + + + + - - @@ -550,6 +557,11 @@ + + + + + @@ -559,15 +571,32 @@ + + + + + + + + + + + + + + + + - + - - - - + + + + + diff --git a/data/syntax/isocpp.xml b/data/syntax/isocpp.xml --- a/data/syntax/isocpp.xml +++ b/data/syntax/isocpp.xml @@ -1,17 +1,28 @@ - - + + + + + + + + - + + + + + + + ]> asm auto class + concept + requires constexpr const_cast decltype @@ -97,6 +110,20 @@ or_eq xor xor_eq + + + + + + + noreturn carries_dependency - + deprecated + + fallthrough + nodiscard + maybe_unused + + likely + unlikely + no_unique_address + + + + + + using @@ -176,71 +221,81 @@ thread_local volatile + + __DATE__ __FILE__ __LINE__ - __DATE__ - __TIME__ - __STDC__ - __STDC_VERSION__ + __STDCPP_DEFAULT_NEW_ALIGNMENT__ + __STDCPP_STRICT_POINTER_SAFETY__ + __STDCPP_THREADS__ __STDC_HOSTED__ __STDC_ISO_10646__ __STDC_MB_MIGHT_NEQ_WC__ + __STDC_VERSION__ + __STDC__ + __TIME__ __cplusplus __func__ + assert + _Pragma + __has_include + + + __VA_ARGS__ + __VA_OPT__ + + + if + + + ifdef + ifndef + + + elif + + + else + + + endif + + + cmakedefine01 + cmakedefine + define + + + include + + + error + line + pragma + undef + warning - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - + + + + + + + + - - - - - - - - - - - + @@ -251,120 +306,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + - - - - - - + + + + - - - - - + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + - - + + + + - + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + - + + - + + - + + - + @@ -380,136 +590,233 @@ - - + + + - - - - - - - + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + - - + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - + + + + + + + + + + - + - - - + + + + + + + - - - - - + + + + + + - + - - + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - + + + - + - + + + + - +