Vscode-cpptools: Linter provides no warnings for invalid C code

Created on 15 Jun 2017  路  10Comments  路  Source: microsoft/vscode-cpptools

See title, create a fresh test.c file with the contents:

#include <stdio.h>

int main()
{
    asdfd;
    return 0;
}

(If) Linting is working properly, asdfd will be underlined with squigglies as you would expect. What you would not expect is that turning it into a function call makes the squigglies go away:

#include <stdio.h>

int main()
{
    asdfd();
    return 0;
}

Furthermore, hovering over it produces the popup int asdfd(), as if it was defined to return int somewhere. This is just silly.

Related to #746

Feature Request Language Service postponed

Most helpful comment

Indeed. That is silly. We'll investigate.

All 10 comments

Indeed. That is silly. We'll investigate.

This only repros in C files, not C++. It looks like the IntelliSense compiler is using the old default int function return value C89 behavior, so asdfd() is being interpreted as a declaration for "int asdfd()", even though we're passing in the C11 flag.

Ok so it's valid C89, but surely this should be an error even in C89?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *line = maloc(100);
    return 0;
}

The misspelled malloc line shows squigglies only when placed outside the main function, but no squigglies inside. Still shows the int hint.

Visual Studio 2017 also shows maloc (or any other undefined function call identifier) as being a function returning an int. I'll ask the VS-side people if they think our shared compiler has a bug.

While it's not valid in the C99 standard, it looks like all the C compilers we support don't support this rule, I assume because it would be a breaking change with C89. So this is currently "by design", but if you can locate us a compiler (or linter) that enforces the non-implicit int behavior, we theoretically could add a new flag to trigger the enforcement behavior.

Sorry I'm not sure I understand, the last example I posted doesn't compile with either GCC or Clang even with -std=c89, yet VS Code doesn't show any error squigglies for it. Is it not an error? Something is definitely wrong here. There should at least be warnings.

test.c:8:11: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
    char *line = maloc(100);
          ^      ~~~~~~~~~~
1 warning generated.
/tmp/test-3f53c3.o: In function `main':
test.c:(.text+0x17): undefined reference to `maloc'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks for the info. The compiler is not giving you an error -- it successfully compiles and fails during linking. IntelliSense currently only gives compiler errors. This sounds like a feature request for warnings and/or linker errors.

Warnings + linker errors sounds good to me.

FYI, you can enable the warnings "experimental/hidden" feature via modifiying the msvc.json file next to the binary by removing the --no_warnings flag. Not sure when we'll get around to adding a setting for that. VS 2017 doesn't have these warnings enabled so it hasn't been tested as much. A previous issue reported was https://github.com/Microsoft/vscode-cpptools/issues/2091 .

image

This feature request has received enough votes to be added to our backlog.

Was this page helpful?
0 / 5 - 0 ratings