microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.45k stars 1.53k forks source link

#include is not taken literally #9258

Closed sewbacca closed 2 years ago

sewbacca commented 2 years ago

Bug type: Language Service

When using #include "..." the language server doesn't take them literally and shows a syntax error, where none is.

Describe the bug

Steps to reproduce Where I found the error:

  1. Clone Love2D
  2. Configure project
  3. Navigate to src/modules/graphics/wrap_Graphics.cpp
  4. Scroll down to line :45
  5. See error

Simpler case:

main.cpp


#include <iostream>

const char str[] =
#include "str.txt"
;

int main(int argc, char const *argv[])
{
    std::cout << str << std::endl;
    return 0;
}

str.txt

"Hello, world!"

Notice: The error vanishes, if const char str[] = ... is moved into main.

Expected behavior No syntax error.

Screenshots grafik

sean-mcmanus commented 2 years ago

Thanks for reporting this. I've filed internal bug 1535519 against our IntelliSense parser shared with VS.

sean-mcmanus commented 2 years ago

It turns out this is "by design" for performance reasons and the suggested workaround is to use

const char str[] = {
#include "str.txt"
};