microsoft / vscode-cpptools

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

VS Code showing error lines for parameter forward declaration syntax #10681

Open aahnik opened 1 year ago

aahnik commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary:

Parameter forward declaration is not supported in C99, but it is supported in modern C. Compiler is not throwing any error, but VS Code shows me error squiggles.

https://stackoverflow.com/questions/17771484/what-is-a-parameter-forward-declaration/17771494#17771494

Steps to reproduce:

  1. In Ubuntu 22.10, VS Code 1.76.1, with C/C++ extension v1.14.4

  2. image

  3. write this code


#include <stdio.h>

void display(int l; int arr[l], int l) {

    printf("[ ");

    for (int i = 0; i < l; i++) {
        printf("%d  ", arr[i]);
    }
    printf(" ]\n");
}

void insertionSort(int l; int arr[l], int l) {
    for (int i = 1; i < l; i++) {
        int curr = arr[i];
        int j = i - 1;
        while (j >= 0 && arr[j] > curr) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = curr;
    }
}

int main() {
    int arr[10] = {2, 5, 1, 4, 9, 8, 3, 10, 11, 7};
    display(arr, 10);
    insertionSort(arr, 10);
    display(arr, 10);
}
  1. See error red lines shown by vs code image

But compiling with gcc -Wall program.c shows no error, and program works as expected.

Debugger Configurations

I am not using debugger

Debugger Logs

debugger not used

Other Extensions

No response

Additional Information

No response

sean-mcmanus commented 1 year ago

I've filed a feature request against our parser at https://developercommunity.visualstudio.com/t/Add-C-IntelliSense-support-for-gcc-exten/10311423 . This is also a sub-issue of https://github.com/microsoft/vscode-cpptools/issues/2172 .