cc-mode gets confused by operator""

[email protected] Sun, 26 Jun 2022 14:34:03 -0700
Newsgroups gmane.emacs.cc-mode.general
Message-ID <[email protected]>
cc-mode doesn't seem to be able to handle user-defined literals.  I've
attached a simple test case.  When editing this file with emacs 28.1 and
cc-mode 5.35.1, you will see the following:


As you can see from the font color, basically the whole rest of the file
starting the line after the operator"" gets treated as a raw multi-line
string.
hexstring.png (image/png, 114.5 KB) - not displayed
hexstring.cc (text/plain, 749 B)
// g++ -std=c++20 hexstring.cc

#include <iostream>
#include <string>

constexpr int
hexdigit(char c)
{
  return (c >= '0' && c <= '9') ? c - '0'
    : (c >= 'a' && c <= 'f') ? c - ('a' - 10)
    : (c >= 'A' && c <= 'F') ? c - ('A' - 10)
    : -1;
}

template<char ...C>
requires (sizeof...(C)%2 == 0 &&
          [](char zero, char x, auto ...rest) {
            return zero == '0' && x == 'x' && ((hexdigit(rest) != -1) && ...);
          }(C...))
constexpr std::string
operator""_hexstring()
{
  constexpr char digits[] = { C... };
  std::string result{};
  for (std::size_t i = 2; i < sizeof(digits); i += 2)
    result += char(hexdigit(digits[i])<<4 | hexdigit(digits[i+1]));
  return result;
}

int
main()
{
  std::cout << 0x400a_hexstring;
}