Fixed #3737 (Preprocessor: __cplusplus always defined for c++ code)

This commit is contained in:
Daniel Marjamäki 2012-05-08 11:49:43 -07:00
parent 99a29eafc9
commit dad2fb6db1
2 changed files with 10 additions and 0 deletions

View File

@ -1498,6 +1498,8 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
// Create a map for the cfg for faster access to defines
std::map<std::string, std::string> cfgmap(getcfgmap(cfg));
if (Path::isCPP(filename) && cfgmap.find("__cplusplus") == cfgmap.end())
cfgmap["__cplusplus"] = "1";
std::stack<std::string> filenames;
filenames.push(filename);

View File

@ -236,6 +236,7 @@ private:
TEST_CASE(predefine2);
TEST_CASE(predefine3);
TEST_CASE(predefine4);
TEST_CASE(predefine5); // automatically define __cplusplus
// Test Preprocessor::simplifyCondition
TEST_CASE(simplifyCondition);
@ -2977,6 +2978,13 @@ private:
ASSERT_EQUALS("char buf[$123];\n", actual);
}
void predefine5() { // #3737 - automatically define __cplusplus
const char code[] = "#ifdef __cplusplus\n123\n#endif";
Preprocessor preprocessor(NULL,this);
ASSERT_EQUALS("\n\n\n", preprocessor.getcode(code, "X=123", "test.c"));
ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(code, "X=123", "test.cpp"));
}
void simplifyCondition() {
// Ticket #2794
std::map<std::string, std::string> cfg;