better-cpp-syntax icon indicating copy to clipboard operation
better-cpp-syntax copied to clipboard

static_assert will break the highlighting of the expression with template parameters

Open Vigilans opened this issue 6 years ago • 2 comments

Checklist

  • [x] This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled"
  • [ ] This bug exists for C
  • [x] This bug exists for C++
  • [ ] This bug exists for Objective-C
  • [ ] This bug exists for Objective-C++

The code with a problem is:

// right
(py::detail::all_of<
    // char will be cast to either signed char or unsigned char
    py::detail::any_of<
        std::is_same<py::enum_<ScopedCharEnum>::Scalar, signed char>, // e.g.
        std::is_same<py::enum_<ScopedCharEnum>::Scalar, unsigned char>>>::value);

// wrong
static_assert(py::detail::all_of<
    // char will be cast to either signed char or unsigned char
    py::detail::any_of<
        std::is_same<py::enum_<ScopedCharEnum>::Scalar, signed char>, // e.g.
        std::is_same<py::enum_<ScopedCharEnum>::Scalar, unsigned char>>>::value);

It looks like:

image

It should look like:

Like this: image

Vigilans avatar Dec 03 '19 05:12 Vigilans

Integrated effect: image

and

image

Vigilans avatar Dec 03 '19 05:12 Vigilans

It looks like it is confusing the comma at column 55 with the start of the static assert message.

Potential solutions:

  1. have the comma lookahead for a double or single quote (per [dcl.pre]/1 only string literals are allowed in the message)
  • doesn't fix static_assert(static_strlen<size_t, "abcdef">::value == 6);
  1. move the message check after the evaluation context
  • I think this may, in some circumstances, cause a lack of tagging for the message (probably minor)
  1. remove the message match entirely (could be useful if 2 leads to inconsistent highlighting)
  2. Attempt to match the entire string literal and lookahead for EOL or )

matter123 avatar Dec 03 '19 16:12 matter123