From 58fe7105f4c8d9f7c8bb9a3022938892ba496675 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 9 Nov 2012 19:53:10 +0100 Subject: [PATCH] Remove C++11 keywords "override", "final" and "constexpr" --- lib/tokenize.cpp | 13 ++++++------- test/testsimplifytokens.cpp | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5627488d2..88e9a0884 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8404,21 +8404,20 @@ void Tokenizer::simplifyAttribute() } } -// Remove "volatile", "inline", "register", and "restrict" +// Remove "volatile", "inline", "register", "restrict", "override", "final" and "constexpr" // "restrict" keyword // - New to 1999 ANSI/ISO C standard // - Not in C++ standard yet void Tokenizer::simplifyKeyword() { - const char *pattern; - + std::string pattern = "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__"; if (_settings->standards.c >= Standards::C99) - pattern = "volatile|inline|__inline|__forceinline|register|restrict|__restrict|__restrict__"; - else - pattern = "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__"; + pattern += "|restrict"; + if (_settings->standards.cpp >= Standards::CPP11) + pattern += "|constexpr|override|final"; for (Token *tok = list.front(); tok; tok = tok->next()) { - while (Token::Match(tok, pattern)) { + while (Token::Match(tok, pattern.c_str())) { tok->deleteThis(); } } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index aea306c88..201d3f134 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -5478,7 +5478,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); checkSimplifyTypedef("typedef constexpr\n"); - ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void simplifyTypedef82() { // ticket #2403 @@ -7671,6 +7671,9 @@ private: ASSERT_EQUALS("int foo ( ) { }", tok("inline int foo ( ) { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("__inline int foo ( ) { }", true)); ASSERT_EQUALS("int foo ( ) { }", tok("__forceinline int foo ( ) { }", true)); + ASSERT_EQUALS("int foo ( ) { }", tok("constexpr int foo() { }", true)); + ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() override ; };", true)); + ASSERT_EQUALS("class C { int f ( ) ; } ;", tok("class C { int f() final ; };", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( likely ( a ) ) { }", true)); ASSERT_EQUALS("if ( a ) { }", tok("if ( unlikely ( a ) ) { }", true)); ASSERT_EQUALS("int * p ;", tok("int * __restrict p;", "test.c"));