Support C++14 digit separators (#7042)

This commit is contained in:
PKEuS 2015-10-14 11:57:20 +02:00
parent 5b5cb63a64
commit a97f6f973f
2 changed files with 14 additions and 6 deletions

View File

@ -632,8 +632,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
// add a suppression if the next token is 'case' or 'default' // add a suppression if the next token is 'case' or 'default'
if (detectFallThroughComments && fallThroughComment) { if (detectFallThroughComments && fallThroughComment) {
const std::string::size_type j = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz", i); const std::string::size_type j = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz", i);
const std::string tok = str.substr(i, j - i); if (str.compare(i, j-i, "case") == 0 || str.compare(i, j-i, "default") == 0)
if (tok == "case" || tok == "default")
suppressionIDs.push_back("switchCaseFallThrough"); suppressionIDs.push_back("switchCaseFallThrough");
fallThroughComment = false; fallThroughComment = false;
} }
@ -662,8 +661,12 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
} }
} }
// C++14 digit separators
if (ch == '\'' && std::isdigit(previous))
; // Just skip it.
// String or char constants.. // String or char constants..
if (ch == '\"' || ch == '\'') { else if (ch == '\"' || ch == '\'') {
code << char(ch); code << char(ch);
char chNext; char chNext;
do { do {
@ -1963,9 +1966,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
{ {
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList; std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
if (!filename.empty()) { if (!filename.empty()) {
ErrorLogger::ErrorMessage::FileLocation loc; ErrorLogger::ErrorMessage::FileLocation loc(filename, linenr);
loc.line = linenr;
loc.setfile(filename);
locationList.push_back(loc); locationList.push_back(loc);
} }
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, _errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,

View File

@ -67,6 +67,7 @@ private:
TEST_CASE(readCode2); // #4308 - convert C++11 raw string to plain old C string TEST_CASE(readCode2); // #4308 - convert C++11 raw string to plain old C string
TEST_CASE(readCode3); TEST_CASE(readCode3);
TEST_CASE(readCode4); // #4351 - escaped whitespace in gcc TEST_CASE(readCode4); // #4351 - escaped whitespace in gcc
TEST_CASE(readCode5); // #7042 - C++14 digit separators
// reading utf-16 file // reading utf-16 file
TEST_CASE(utf16); TEST_CASE(utf16);
@ -336,6 +337,12 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void readCode5() {
const char code[] = "int i = 0x1000'00;";
ASSERT_EQUALS("int i = 0x100000;", preprocessorRead(code));
ASSERT_EQUALS("", errout.str());
}
void utf16() { void utf16() {