microsoft / vscode-cpptools

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

identifier "size_t" is undefined (g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0) #12990

Open GuigzLab opened 3 days ago

GuigzLab commented 3 days ago

Environment

Bug Summary and Steps to Reproduce

Hi, I recently started to experience an issue using vscode IntelliSense, size_t : identifier "size_t" is undefined C/C++(20)

I'm compiling fine though.

I'm using vscode in a docker using the Dev Containers extension.

I tried adding this part from this issue but nothing changed:

    "C_Cpp.default.defines": [
        "__building_module(x)=0"
    ],

Depending on the files I'm working on, I either get _identifier "sizet" is undefined or It's linked to a redefinition of size_t from different modules (gdal, curl...)

Configuration and Logs

Here is my configuration on the remote host:

{
    "C_Cpp.default.includePath": [
        "${default}",
        "${workspaceFolder}/**",
    ],
    // Folders to exclude from workspace parsing    
    "C_Cpp.files.exclude": {
        "**/build/**": true,
        "/home/builder/workspace/data/**": true,
    },
    // Files changes to exclude    
    "files.watcherExclude": {
        "**/build/**": true,
        "/home/builder/workspace/data/**": true,
    },
    // Files search to exclude    
    "search.exclude": {
        "**/build/**": true,
        "/home/builder/workspace/data/**": true,
    },
    "C_Cpp.default.intelliSenseMode": "linux-gcc-x64",
    "C_Cpp.default.cppStandard": "c++17",
    "C_Cpp.default.cStandard": "c17",
    "C_Cpp.default.compilerPath": "/usr/bin/g++",
    "C_Cpp.default.defines": [
        "__building_module(x)=0"
    ],
}

Other Extensions

Dev Containers

Additional context

No response

sean-mcmanus commented 3 days ago

@GuigzLab What version of g++? Can you confirm that it doesn't repro with 1.21.6? What is the minimal repro code? Does it repro with

#include <cstddef>

size_t i;

If you use Go to Def on cstddef are you able to locate the first file that shows an error? And/or use Go to Def on size_t. That could help locate the source of issue the issue that is causing the definition of size_t to not be parsed.

GuigzLab commented 7 hours ago

@GuigzLab What version of g++?

g++ version is g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Can you confirm that it doesn't repro with 1.21.6? What is the minimal repro code? Does it repro with

include

size_t i;

It doesn't repro with that code, minimal repro code is with #include <gdal_priv.h> in my case but any lib that redefines size_t will do it

If you use Go to Def on cstddef are you able to locate the first file that shows an error? And/or use Go to Def on size_t. That could help locate the source of issue the issue that is causing the definition of size_t to not be parsed.

When only using cstddef it works fine, but any time I include a library containing a redefinition of size_t i get an error, with gdal I get this when hovering a _sizet

typedef <error-type> size_t(<error-type>)
Callback used by VSIStdoutSetRedirection()

So if I try to use it in a for loop for example, it will display errors, unless I use std::size_t but I would have to change files I don't have access to...

    for (size_t i = 0; i < 10; i++)
    {
        std::cout << i << std::endl;
    }

Gets me this error: function "i" may not be initializedC/C++(145)

Here is what's in the header, in file cpl_vsi.h from gdal lib:

/** Callback used by VSIStdoutSetRedirection() */
typedef size_t (*VSIWriteFunction)(const void *ptr, size_t size, size_t nmemb,
                                   FILE *stream);