C++17: Support "if constexpr" (by simplifying it to plain if() statement)

This might lead to complaints about constant expressions as if() statement, but should fix syntax errors.
This commit is contained in:
PKEuS 2018-04-09 11:42:38 +02:00
parent 49a3f32f80
commit 17b4721bd2
2 changed files with 7 additions and 0 deletions

View File

@ -3532,6 +3532,8 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// 'for each ( )' -> 'asm ( )'
tok->str("asm");
tok->deleteNext();
} else if (tok->strAt(1) == "constexpr") {
tok->deleteNext();
} else {
syntaxError(tok);
}

View File

@ -82,6 +82,7 @@ private:
TEST_CASE(syntax_case_default);
TEST_CASE(foreach); // #3690
TEST_CASE(ifconstexpr);
TEST_CASE(combineOperators);
@ -905,6 +906,10 @@ private:
ASSERT_EQUALS("void f ( ) { asm ( \"char c in MyString\" ) { Console :: Write ( c ) ; } }", tokenizeAndStringify(code));
}
void ifconstexpr() {
ASSERT_EQUALS("void f ( ) { if ( FOO ) { bar ( c ) ; } }", tokenizeAndStringify("void f() { if constexpr ( FOO ) { bar(c); } }"));
}
void combineOperators() {
ASSERT_EQUALS("; private: ;", tokenizeAndStringify(";private:;", false));
ASSERT_EQUALS("; protected: ;", tokenizeAndStringify(";protected:;", false));