Skip to content

__Generic cases cannot contains both enum and size_t #14122

@loynoir

Description

@loynoir

bug

__Generic cases cannot contains both enum and size_t within editor

version

1.29.3

description

console output
expected: foo1
expected: foo2
expected: size_t
workaround1: foo1
workaround1: foo2
workaround1: unkown
workaround2: unknown
workaround2: unknown
workaround2: size_t
vscode problems output
[{
	"resource": "/path/to/reproduce.c",
	"owner": "C/C++: IntelliSense",
	"code": "2534",
	"severity": 8,
	"message": "duplicate association type (\"size_t\" (aka \"unsigned int\")) in _Generic selection",
	"source": "C/C++",
	"startLineNumber": 30,
	"startColumn": 3,
	"endLineNumber": 30,
	"endColumn": 11,
	"origin": "extHost2"
},{
	"resource": "/path/to/reproduce.c",
	"owner": "C/C++: IntelliSense",
	"code": "2534",
	"severity": 8,
	"message": "duplicate association type (\"size_t\" (aka \"unsigned int\")) in _Generic selection",
	"source": "C/C++",
	"startLineNumber": 32,
	"startColumn": 3,
	"endLineNumber": 32,
	"endColumn": 11,
	"origin": "extHost2"
},{
	"resource": "/path/to/reproduce.c",
	"owner": "C/C++: IntelliSense",
	"code": "3227",
	"severity": 8,
	"message": "_Generic construct matches multiple types",
	"source": "C/C++",
	"startLineNumber": 34,
	"startColumn": 3,
	"endLineNumber": 34,
	"endColumn": 11,
	"relatedInformation": [
		{
			"startLineNumber": 34,
			"startColumn": 3,
			"endLineNumber": 34,
			"endColumn": 11,
			"message": "the other match is \"foo1\" (aka \"enum <unnamed>\")",
			"resource": "/path/to/reproduce.c"
		}
	],
	"origin": "extHost2"
},{
	"resource": "/path/to/reproduce.c",
	"owner": "C/C++: IntelliSense",
	"code": "3227",
	"severity": 8,
	"message": "_Generic construct matches multiple types",
	"source": "C/C++",
	"startLineNumber": 39,
	"startColumn": 3,
	"endLineNumber": 39,
	"endColumn": 14,
	"relatedInformation": [
		{
			"startLineNumber": 39,
			"startColumn": 3,
			"endLineNumber": 39,
			"endColumn": 14,
			"message": "the other match is \"foo1\" (aka \"enum <unnamed>\")",
			"resource": "/path/to/reproduce.c"
		}
	],
	"origin": "extHost2"
}]

When expected(X) = GENERIC(enum, size_t)(X)

#define expected(X)                                                            \
  printf("%s: %s\n", "expected",                                               \
         _Generic((X), foo1: "foo1", foo2: "foo2", size_t: "size_t"))
  • expected(enum) is OK in terminal, ERR in vscode
  • expected(size_t) is OK in terminal, ERR in vscode

When workaround1(X) = GENERIC(enum, default)(X)

  • workaround1(enum) is OK in terminal, OK in vscode
  • workaround1(size_t) is unknown in terminal, ERR in vscode

When workaround2(X) = GENERIC(size_t, default)(X)

  • workaround2(enum) is unknown in terminal, OK in vscode
  • workaround2(size_t) is OK in terminal, OK in vscode

reproduce

code

/path/to/reproduce.c

#include <stddef.h>
#include <stdio.h>

#define expected(X)                                                            \
  printf("%s: %s\n", "expected",                                               \
         _Generic((X), foo1: "foo1", foo2: "foo2", size_t: "size_t"))

#define workaround1(X)                                                         \
  printf("%s: %s\n", "workaround1",                                            \
         _Generic((X), foo1: "foo1", foo2: "foo2", default: "unkown"))

#define workaround2(X)                                                         \
  printf("%s: %s\n", "workaround2",                                            \
         _Generic((X), size_t: "size_t", default: "unknown"))

typedef enum {
  foo1_default,
} foo1;

typedef enum {
  foo2_default,
} foo2;

int main() {
  foo1 value_foo1 = foo1_default;
  foo2 value_foo2 = foo2_default;
  size_t value_size_t = 0;

  // editor error
  expected(value_foo1);
  // editor error
  expected(value_foo2);
  // editor error
  expected(value_size_t);

  workaround1(value_foo1);
  workaround1(value_foo2);
  // editor error
  workaround1(value_size_t);

  workaround2(value_foo1);
  workaround2(value_foo2);
  workaround2(value_size_t);

  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions