Skip to content

Commit

Permalink
Fix #12869: dumpfile: should say if function has a const/pure attribu…
Browse files Browse the repository at this point in the history
…te (#6566)
  • Loading branch information
swasti16 authored Jul 5, 2024
1 parent d34e645 commit 1275c77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4255,6 +4255,10 @@ void SymbolDatabase::printXml(std::ostream &out) const
outs += id_string(overriddenFunction);
outs += "\"";
}
if (function->isAttributeConst())
outs += " isAttributeConst=\"true\"";
if (function->isAttributePure())
outs += " isAttributePure=\"true\"";
if (function->argCount() == 0U)
outs += "/>\n";
else {
Expand Down
23 changes: 23 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(throwFunction1);
TEST_CASE(throwFunction2);

TEST_CASE(constAttributeFunction);
TEST_CASE(pureAttributeFunction);

TEST_CASE(nothrowAttributeFunction);
TEST_CASE(nothrowDeclspecFunction);

Expand Down Expand Up @@ -8395,6 +8398,26 @@ class TestSymbolDatabase : public TestFixture {
CLASS_FUNC_THROW(func12, fred);
}

void constAttributeFunction() {
GET_SYMBOL_DB("void func(void) __attribute__((const));");
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS(true, db != nullptr); // not null

const Function* func = findFunctionByName("func", &db->scopeList.front());
ASSERT_EQUALS(true, func != nullptr);
ASSERT_EQUALS(true, func->isAttributeConst());
}

void pureAttributeFunction() {
GET_SYMBOL_DB("void func(void) __attribute__((pure));");
ASSERT_EQUALS("", errout_str());
ASSERT_EQUALS(true, db != nullptr); // not null

const Function* func = findFunctionByName("func", &db->scopeList.front());
ASSERT_EQUALS(true, func != nullptr);
ASSERT_EQUALS(true, func->isAttributePure());
}

void nothrowAttributeFunction() {
GET_SYMBOL_DB("void func() __attribute__((nothrow));\n"
"void func() { }");
Expand Down

0 comments on commit 1275c77

Please sign in to comment.