Fixed #4617 (False positive (style): noexcept for constructors)
This commit is contained in:
parent
4ae65ea454
commit
94da3bd57f
|
@ -8065,13 +8065,18 @@ void Tokenizer::removeExceptionSpecifications()
|
|||
return;
|
||||
|
||||
for (Token* tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, ") const| throw (")) {
|
||||
if (Token::Match(tok, ") const| throw|noexcept (")) {
|
||||
if (tok->next()->str() == "const") {
|
||||
Token::eraseTokens(tok->next(), tok->linkAt(3));
|
||||
tok = tok->next();
|
||||
} else
|
||||
Token::eraseTokens(tok, tok->linkAt(2));
|
||||
tok->deleteNext();
|
||||
} else if (Token::Match(tok, ") const| noexcept ;|{|const")) {
|
||||
if (tok->next()->str() == "const")
|
||||
tok->next()->deleteNext();
|
||||
else
|
||||
tok->deleteNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ private:
|
|||
TEST_CASE(simple10); // ticket #4388
|
||||
TEST_CASE(simple11); // ticket #4536
|
||||
TEST_CASE(simple12); // ticket #4620
|
||||
TEST_CASE(simple13); // ticket #4617
|
||||
|
||||
TEST_CASE(initvar_with_this); // BUG 2190300
|
||||
TEST_CASE(initvar_if); // BUG 2190290
|
||||
|
@ -375,6 +376,36 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void simple13() { // ticket #4617
|
||||
check("class Fred {\n"
|
||||
" int x;\n"
|
||||
"public:\n"
|
||||
" Fred() noexcept;\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Fred {\n"
|
||||
" int x;\n"
|
||||
"public:\n"
|
||||
" Fred() noexcept(true);\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Fred {\n"
|
||||
" int x;\n"
|
||||
"public:\n"
|
||||
" Fred() noexcept { x = 0; }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Fred {\n"
|
||||
" int x;\n"
|
||||
"public:\n"
|
||||
" Fred() noexcept(true) { x = 0; }\n"
|
||||
"};\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void initvar_with_this() {
|
||||
check("struct Fred\n"
|
||||
"{\n"
|
||||
|
|
|
@ -380,6 +380,7 @@ private:
|
|||
TEST_CASE(removeExceptionSpecification3);
|
||||
TEST_CASE(removeExceptionSpecification4);
|
||||
TEST_CASE(removeExceptionSpecification5);
|
||||
TEST_CASE(removeExceptionSpecification6); // #4617
|
||||
|
||||
TEST_CASE(gt); // use "<" comparisons instead of ">"
|
||||
|
||||
|
@ -6132,6 +6133,46 @@ private:
|
|||
tokenizeAndStringify("void foo (struct S1, struct S2) throw();"));
|
||||
}
|
||||
|
||||
void removeExceptionSpecification6() { // #4617
|
||||
ASSERT_EQUALS("void foo ( ) ;",
|
||||
tokenizeAndStringify("void foo () noexcept;"));
|
||||
ASSERT_EQUALS("void foo ( ) { }",
|
||||
tokenizeAndStringify("void foo () noexcept { }"));
|
||||
ASSERT_EQUALS("void foo ( ) ;",
|
||||
tokenizeAndStringify("void foo () noexcept(true);"));
|
||||
ASSERT_EQUALS("void foo ( ) { }",
|
||||
tokenizeAndStringify("void foo () noexcept(true) { }"));
|
||||
ASSERT_EQUALS("void foo ( ) ;",
|
||||
tokenizeAndStringify("void foo () noexcept(noexcept(true));"));
|
||||
ASSERT_EQUALS("void foo ( ) { }",
|
||||
tokenizeAndStringify("void foo () noexcept(noexcept(true)) { }"));
|
||||
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () const noexcept;"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () const noexcept { }"));
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () const noexcept(true);"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () const noexcept(true) { }"));
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () const noexcept(noexcept(true));"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () const noexcept(noexcept(true)) { }"));
|
||||
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () noexcept const;"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () noexcept const { }"));
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () noexcept(true) const;"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () noexcept(true) const { }"));
|
||||
ASSERT_EQUALS("void foo ( ) const ;",
|
||||
tokenizeAndStringify("void foo () noexcept(noexcept(true)) const;"));
|
||||
ASSERT_EQUALS("void foo ( ) const { }",
|
||||
tokenizeAndStringify("void foo () noexcept(noexcept(true)) const { }"));
|
||||
}
|
||||
|
||||
void gt() {
|
||||
ASSERT_EQUALS("( i < 10 )", tokenizeAndStringify("(10>i)"));
|
||||
|
|
Loading…
Reference in New Issue