microsoft / vscode-cpptools

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

__has_include does not search Xcode framework path #10840

Open maruyama-tomo opened 1 year ago

maruyama-tomo commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

#include <CoreFoundation/CFString.h> works fine. Also #if __has_include(<unistd.h>) works well. But #if __has_include(<CoreFoundation/CFString.h>) does not.

Steps to reproduce:

  1. Set "cppStandard": "c++17"
  2. Put the code below:
    #if !__has_include(<CoreFoundation/CFString.h>)
    #error CFString.h not found!
    #endif
  3. See error on vscode editor pane.

Expected behavior:

No error shows.

Actual behavior:

VS Code shows the error. But it compiles with Xcode clang++ successfully.

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-clang-x64"
        }
    ],
    "version": 4
}

Diagnostics log:

-------- Diagnostics - 4/19/2023, 5:07:01 PM
Version: 1.14.5
Current Configuration:
{
    "name": "Mac",
    "includePath": [
        "/private/tmp/vscode-issue/**"
    ],
    "defines": [],
    "macFrameworkPath": [
        "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
    ],
    "compilerPath": "/usr/bin/clang",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "macos-clang-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ /private/tmp/vscode-issue/main.cc ]:
    /private/tmp/vscode-issue/main.cc
Translation Unit Configurations:
[ /private/tmp/vscode-issue/main.cc ]:
    Process ID: 34806
    Memory Usage: 70 MB
    Compiler Path: /usr/bin/clang
    Includes:
        /usr/local/include
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
    Frameworks:
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
    Standard Version: c++17
    IntelliSense Mode: macos-clang-x64
    Other Flags:
        --clang
        --clang_version=110000
Total Memory Usage: 70 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 26339

Other Extensions

No response

Additional context

example code:

main.cc

#if !__has_include(<iostream>)
#error <iostream> not found
#endif

#if !__has_include(<CoreFoundation/CFString.h>)
#error <CoreFoundation/CFString.h> not found
#endif

#include <iostream>

#include <CoreFoundation/CFString.h>

int main()
{
    std::cout << "CFString Type ID: " << ::CFStringGetTypeID() << std::endl;
    return 0;
}

command:

clang++ -framework CoreFoundation main.cc
Zingam commented 1 year ago

Frameworks are not very well supported. I have observed various navigation and intellisense issues. I believe there are a few issue reports.