Vscode-cpptools: A value of type X cannot be used to initialize an entity of type X

Created on 25 Feb 2019  路  11Comments  路  Source: microsoft/vscode-cpptools

Type: LanguageService

Describe the bug

  • OS and Version: macOS 10.14.3
  • VS Code Version: 1.13.1
  • C/C++ Extension Version: 0.21.0
  • Other extensions you installed (and if the issue persists after disabling them): too many... yes
  • A clear and concise description of what the bug is: A value of type X cannot be used to initialize an entity of type X

To Reproduce

  1. Create a new document, select the language to be "C++", and type:
struct Value {
    struct Array;
    struct Dict;
    struct Primitive;

    Value() {}
    virtual ~Value() {}

    virtual Array * asArray() { assert(false); }
    virtual Dict * asDict() { assert(false); }
    virtual Primitive * asPrimitive() { assert(false); }

    int asInt();
    double asDouble();
    std::string asDate();
    std::string asString();
};

struct Value::Array : public Value {

    Array() {}
    ~Array() {}

    Value::Array * asArray() { 
        Value::Array * result = this; 
        return result;
    }
};
  1. Wait for the IntelliSence's error squiggle and message (shown in screenshot).

Expected behavior

This is a legitimate assignment and there should not be an error.

Screenshots
screen shot 2019-02-24 at 23 38 36

other info:
Might related to this on StackOverflow, though it's not clear whether the problem described in that post occurred in VSCode or other IDE/editor.

Language Service Visual Studio bug more votes needed

Most helpful comment

To suppress this error, you can add

#if __INTELLISENSE__
#pragma diag_suppress 144
#endif

to some code in the TU, such as in a forcedInclude:

            "forcedInclude": [
                "${workspaceFolder}/ingoreIntelliSenseErrors.h"
            ]

Starting with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders4, the error codes are added to the IntelliSense errors, so other invalid errors can be suppressed as well.

All 11 comments

However, this is in a .h file. Moving the definition of asArray() to another .cpp file solves the issue.
screen shot 2019-02-24 at 23 44 37

I'm able to repro the bug. It's a bug inherited from VS. I normally would create a bug on VS myself, but they've asked us to have users to report it themselves at https://developercommunity.visualstudio.com/content/problem/post.html?space=62 -- simply pasting a link to this bug report would be good enough. If that is too much of a burden for you, let me know, and I'll open the bug myself.

@sean-mcmanus hi thanks for your feedback! However it requires an MS account but I don't have one and don't intend to create one at the moment...

If you click the "Sign-in options" you should be able to login using your GitHub account.

image

I filed a VS bug https://developercommunity.visualstudio.com/content/problem/471939/c-intellisense-incorrectly-show-a-value-of-type-x.html . But it sounds like they want more upvotes before they'll fix it.

Looks like this was already reported in July (from the Stack Overflow): https://developercommunity.visualstudio.com/content/problem/293884/e0144-being-reported-for-valid-code-intellisense-e.html . It needs more upvotes.

encountered the same issue

@stcheng Are you able to upvote the VS issue at https://developercommunity.visualstudio.com/content/problem/293884/e0144-being-reported-for-valid-code-intellisense-e.html ? Or if enough people can upvote this GitHub issue we may be able to get them to re-open it.

Just hit this myself.

Annoying problem - please fix.

To suppress this error, you can add

#if __INTELLISENSE__
#pragma diag_suppress 144
#endif

to some code in the TU, such as in a forcedInclude:

            "forcedInclude": [
                "${workspaceFolder}/ingoreIntelliSenseErrors.h"
            ]

Starting with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders4, the error codes are added to the IntelliSense errors, so other invalid errors can be suppressed as well.

Was this page helpful?
0 / 5 - 0 ratings