jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
156 stars 29 forks source link

`meta.parameter` scope leaks #654

Open alexr00 opened 7 months ago

alexr00 commented 7 months ago

Checklist

The code with a problem is:

#include <vector>

std::vector<uint64_t> test(1 << 22);

int main() {
  for (int i = 0; i < (1 << 22); i++) {
    test[i] = i;
  }
  while (true) {
    switch (test[0] % 4) {
      case 0:
        test[0] = test[0] * 0x5deece66d + 0xb;
        break;
      case 1:
        test[0] = test[0] * 0x5deece66d + 0xb;
        break;
      case 2:
        test[0] = test[0] * 0x5deece66d + 0xb;
        break;
      case 3:
        test[0] = test[0] * 0x5deece66d + 0xb;
        break;
    }
  }
  return 0;
}

It looks like:

It looks like meta.parameter.cpp is leaking out of the line std::vector<uint64_t> test(1 << 22);

image

Originally from @clysto in https://github.com/microsoft/vscode/issues/207184

jeff-hykin commented 6 months ago

@clysto I pushed a fix for this specific case, but stuff like

constexpr int a = 5;
std::vector<uint64_t> test(a << 22);

Is still broken because a full/generic fix is going to be tough. Not only does it involve the classic turbofish problem (which is sometimes totally unsolvable), but it also involves function-definition-vs-function-call which for Textmate, is always very hard, and sometimes unsolvable.