Ticket #7850: Properly handle C functions called "class".

This commit is contained in:
Simon Martin 2017-01-06 21:16:28 +01:00
parent c2a1c4056f
commit bd92ddd386
2 changed files with 12 additions and 1 deletions

View File

@ -3056,7 +3056,7 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
const Token *nameTok = classDef;
if (!classDef) {
type = Scope::eGlobal;
} else if (classDef->str() == "class") {
} else if (classDef->str() == "class" && check && check->isCPP()) {
type = Scope::eClass;
nameTok = nameTok->next();
} else if (classDef->str() == "struct") {

View File

@ -273,6 +273,7 @@ private:
TEST_CASE(vardecl24); // #4187 - variable declaration within lambda function
TEST_CASE(vardecl25); // #4799 - segmentation fault
TEST_CASE(vardecl26); // #5907 - incorrect handling of extern declarations
TEST_CASE(vardecl27); // #7850 - crash on valid C code
TEST_CASE(vardecl_stl_1);
TEST_CASE(vardecl_stl_2);
TEST_CASE(vardecl_template_1);
@ -3938,6 +3939,16 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
}
void vardecl27() { // #7850
const char code[] = "extern int foo(char);\n"
"void* class(char c) {\n"
" if (foo(c))\n"
" return 0;\n"
" return 0;\n"
"}";
tokenizeAndStringify(code, /*simplify=*/false, /*expand=*/true, Settings::Native, "test.c");
}
void volatile_variables() {
const char code[] = "volatile int a=0;\n"
"volatile int b=0;\n"