From 17b4721bd261d2ce5de6ca221c303276b0c5fe55 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 9 Apr 2018 11:42:38 +0200 Subject: [PATCH] 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. --- lib/tokenize.cpp | 2 ++ test/testtokenize.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index faa12f994..2f481d580 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b3935c77d..3fbe8081d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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));