Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,19 @@ std::set<std::string> Preprocessor::getConfigs() const

std::set<std::string> defined = { "__cplusplus" };

// Insert library defines
for (const auto &define : mSettings.library.defines()) {

const std::string::size_type paren = define.find("(");
const std::string::size_type space = define.find(" ");
std::string::size_type end = space;

if (paren != std::string::npos && paren < space)
end = paren;

defined.insert(define.substr(0, end));
}

::getConfigs(mTokens, defined, mSettings.userDefines, mSettings.userUndefs, ret);

for (const auto &filedata : mFileCache) {
Expand Down
20 changes: 19 additions & 1 deletion test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ class TestPreprocessor : public TestFixture {
TEST_CASE(getConfigs8); // #if A==1 => cfg: A=1
TEST_CASE(getConfigs10); // #5139
TEST_CASE(getConfigs11); // #9832 - include guards
TEST_CASE(getConfigs12); // #14222
TEST_CASE(getConfigs13); // #14222
TEST_CASE(getConfigsError);

TEST_CASE(getConfigsD1);
Expand Down Expand Up @@ -357,12 +359,14 @@ class TestPreprocessor : public TestFixture {
}

template<size_t size>
std::string getConfigsStr(const char (&code)[size], const char *arg = nullptr) {
std::string getConfigsStr(const char (&code)[size], const char *arg = nullptr, const char *library = nullptr) {
Settings settings;
if (arg && std::strncmp(arg,"-D",2)==0)
settings.userDefines = arg + 2;
if (arg && std::strncmp(arg,"-U",2)==0)
settings.userUndefs.insert(arg+2);
if (library)
ASSERT(settings.library.load("", library, false).errorcode == Library::ErrorCode::OK);
std::vector<std::string> files;
// TODO: this adds an empty filename
simplecpp::TokenList tokens(code,files);
Expand Down Expand Up @@ -2264,6 +2268,20 @@ class TestPreprocessor : public TestFixture {
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}

void getConfigs12() { // #14222
const char filedata[] = "#ifdef INT8_MAX\n"
"INT8_MAX\n"
"#endif\n";
ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "std.cfg"));
}

void getConfigs13() { // #14222
const char filedata[] = "#ifdef __builtin_bswap16\n"
"__builtin_bswap16(x);\n"
"#endif\n";
ASSERT_EQUALS("\n", getConfigsStr(filedata, nullptr, "gnu.cfg"));
}

void getConfigsError() {
const char filedata1[] = "#ifndef X\n"
"#error \"!X\"\n"
Expand Down
Loading