Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no suitable constructor exists to convert from "int" to "std::expected<int, std::string>" but compiles fine #11140

Closed
akarampetsos opened this issue Jun 28, 2023 · 2 comments

Comments

@akarampetsos
Copy link

akarampetsos commented Jun 28, 2023

Environment

  • OS and Version: Fedora 38
  • VS Code Version: 1.79.2
  • C/C++ Extension Version: 1.16.3

Bug Summary and Steps to Reproduce

Bug Summary:

Using std::expected produces errors

Steps to reproduce:

  1. Create main.cpp with the following code:
#include <iostream>

#include <string>
#include <expected>

int main() {
    std::expected<int, std::string> t = 1;

    std::cout << t.value() << std::endl;

    return 0;
}
  1. Observe an error mark under 1 with the message no suitable constructor exists to convert from "int" to "std::expected<int, std::string>"C/C++(415)

Expected behavior:

No error message. Compiling with g++ main.cpp -std=c++23 works with an output of 1 as expected.

Configuration and Logs

  • c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "intelliSenseMode": "${default}",
            "cppStandard": "c++23"
        }
    ],
    "version": 4
}
  • C/C++: Log Diagnostics
-------- Diagnostics - 6/28/2023, 9:31:57 PM
Version: 1.16.3
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "/home/alex/dev/test-cpp-23/**"
    ],
    "defines": [],
    "intelliSenseMode": "linux-gcc-x64",
    "cppStandard": "c++23",
    "compilerPathIsExplicit": false,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": false,
    "macFrameworkPath": [],
    "cStandard": "c23",
    "mergeConfigurations": false,
    "compilerPath": "/usr/bin/gcc",
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
cpptools version (native): 1.16.3.0
Translation Unit Mappings:
[ /home/alex/dev/test-cpp-23/main.cpp ]:
    /home/alex/dev/test-cpp-23/main.cpp
Translation Unit Configurations:
[ /home/alex/dev/test-cpp-23/main.cpp ]:
    Process ID: 18931
    Memory Usage: 70 MB
    Compiler Path: /usr/bin/gcc
    Includes:
        /usr/include/c++/13
        /usr/include/c++/13/x86_64-redhat-linux
        /usr/include/c++/13/backward
        /usr/lib/gcc/x86_64-redhat-linux/13/include
        /usr/local/include
        /usr/include
    Standard Version: c++23
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --g++
        --gnu_version=130101
Total Memory Usage: 70 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 3684
Number of files parsed: 509
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/activeDocumentChange: file:///home/alex/dev/test-cpp-23/main.cpp
LSP: cpptools/textEditorSelectionChange
LSP: cpptools/getCodeActions: file:///home/alex/dev/test-cpp-23/main.cpp (id: 373)
LSP: textDocument/willSaveWaitUntil: file:///home/alex/dev/test-cpp-23/main.cpp (id: 374)
willSaveWaitUntil: 0ms
LSP: textDocument/didSave: file:///home/alex/dev/test-cpp-23/main.cpp
  tag parsing file: /home/alex/dev/test-cpp-23/main.cpp
LSP: cpptools/fileChanged: file:///home/alex/dev/test-cpp-23/main.cpp
idle loop: reparsing the active document
Checking for syntax errors: /home/alex/dev/test-cpp-23/main.cpp
Queueing IntelliSense update for files in translation unit of: /home/alex/dev/test-cpp-23/main.cpp
Error squiggle count: 1
Update IntelliSense time (sec): 0.262
LSP: cpptools/getSemanticTokens: file:///home/alex/dev/test-cpp-23/main.cpp (id: 375)
LSP: cpptools/getFoldingRanges: file:///home/alex/dev/test-cpp-23/main.cpp (id: 376)
LSP: cpptools/getCodeActions: file:///home/alex/dev/test-cpp-23/main.cpp (id: 377)

Additional context

I also found another user who had the same issue and posted a question on stack overflow about it. He suggested that changing the compiler to an older one helped but the issue still persists for me even if I do that. My version of gcc is gcc version 13.1.1 20230614 (Red Hat 13.1.1-4) (GCC)

@Colengms
Copy link
Contributor

This is a duplicate of #11038 , due to underlying unchecked use of __is_convertible. Closing as a duplicate.

@Colengms Colengms closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2023
@michelleangela
Copy link
Contributor

Fix available in pre-release https://github.com/microsoft/vscode-cpptools/releases/tag/v1.17.0.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants