Skip to content

Commit 8a6c401

Browse files
committed
add tests
1 parent 9b3b160 commit 8a6c401

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

test/testother.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12707,6 +12707,16 @@ class TestOther : public TestFixture {
1270712707
ASSERT_EQUALS("[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n"
1270812708
"[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n",
1270912709
errout_str());
12710+
12711+
check("int ifunc(int x);\n"
12712+
"unsigned int ufunc(unsigned int x);\n"
12713+
"void f(void)\n"
12714+
"{\n"
12715+
" unsigned int x = 0;\n"
12716+
" if (_Generic(x, int: ifunc, unsigned int: ufunc)(x) < 0) {}\n"
12717+
"}\n", dinit(CheckOptions, $.cpp = false));
12718+
ASSERT_EQUALS("[test.c:6:57]: (style) Checking if unsigned expression '_Generic ( x,int:ifunc,unsigned int:ufunc)(x)' is less than zero. [unsignedLessThanZero]\n",
12719+
errout_str());
1271012720
}
1271112721

1271212722
void doubleMove1() {

test/testsymboldatabase.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ class TestSymbolDatabase : public TestFixture {
595595
TEST_CASE(valueTypeThis);
596596
TEST_CASE(valueTypeChar);
597597
TEST_CASE(valueTypeRValueReference);
598+
TEST_CASE(valueTypeGeneric);
598599

599600
TEST_CASE(variadic1); // #7453
600601
TEST_CASE(variadic2); // #7649
@@ -10401,6 +10402,72 @@ class TestSymbolDatabase : public TestFixture {
1040110402
TODO_ASSERT_EQUALS("", "bool", typeOf("void f(std::string&& s = {})\n", "&&"));
1040210403
}
1040310404

10405+
void valueTypeGeneric() {
10406+
ASSERT_EQUALS("float", typeOf(
10407+
"float floatvar;\n"
10408+
"int intvar;\n"
10409+
"void testfunc() {\n"
10410+
" int controlvar;\n"
10411+
" auto testvar = _Generic(controlvar, int: floatvar, default: intvar);\n"
10412+
"}\n", "testvar"));
10413+
10414+
ASSERT_EQUALS("signed int", typeOf(
10415+
"float floatvar;\n"
10416+
"int intvar;\n"
10417+
"void testfunc() {\n"
10418+
" float controlvar;\n"
10419+
" auto testvar = _Generic(controlvar, int: floatvar, default: intvar);\n"
10420+
"}\n", "testvar"));
10421+
10422+
ASSERT_EQUALS("float", typeOf(
10423+
"float floatvar;\n"
10424+
"int intvar;\n"
10425+
"void testfunc() {\n"
10426+
" int *const controlvar;\n"
10427+
" auto testvar = _Generic(controlvar, int*: floatvar, default: intvar);\n"
10428+
"}\n", "testvar"));
10429+
10430+
ASSERT_EQUALS("signed int", typeOf(
10431+
"float floatvar;\n"
10432+
"int intvar;\n"
10433+
"void testfunc() {\n"
10434+
" const int *controlvar;\n"
10435+
" auto testvar = _Generic(controlvar, int*: floatvar, default: intvar);\n"
10436+
"}\n", "testvar"));
10437+
10438+
ASSERT_EQUALS("float", typeOf(
10439+
"float floatfunc();\n"
10440+
"int intfunc();\n"
10441+
"void testfunc() {\n"
10442+
" int controlvar;\n"
10443+
" auto testvar = _Generic(controlvar, int: floatfunc, default: intfunc)();\n"
10444+
"}\n", "testvar"));
10445+
10446+
ASSERT_EQUALS("signed int", typeOf(
10447+
"float floatfunc();\n"
10448+
"int intfunc();\n"
10449+
"void testfunc() {\n"
10450+
" float controlvar;\n"
10451+
" auto testvar = _Generic(controlvar, int: floatfunc, default: intfunc)();\n"
10452+
"}\n", "testvar"));
10453+
10454+
ASSERT_EQUALS("float", typeOf(
10455+
"float floatfunc();\n"
10456+
"int intfunc();\n"
10457+
"void testfunc() {\n"
10458+
" int *const controlvar;\n"
10459+
" auto testvar = _Generic(controlvar, int*: floatfunc, default: intfunc)();\n"
10460+
"}\n", "testvar"));
10461+
10462+
ASSERT_EQUALS("signed int", typeOf(
10463+
"float floatfunc();\n"
10464+
"int intfunc();\n"
10465+
"void testfunc() {\n"
10466+
" const int *controlvar;\n"
10467+
" auto testvar = _Generic(controlvar, int*: floatfunc, default: intfunc)();\n"
10468+
"}\n", "testvar"));
10469+
}
10470+
1040410471
void variadic1() { // #7453
1040510472
{
1040610473
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"

0 commit comments

Comments
 (0)