Skip to content

Commit 34486df

Browse files
Fix #14693 False positive: null pointer, std::string && val = {} (#8499)
1 parent b9513d3 commit 34486df

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
446446
if (!Token::Match(tok->previous(), "( %name%"))
447447
return tok;
448448
Token *vartok = tok;
449-
while (Token::Match(vartok, "%name%|*|&|::|<")) {
449+
while (Token::Match(vartok, "%name%|*|&|&&|::|<")) {
450450
if (vartok->str() == "<") {
451451
if (vartok->link())
452452
vartok = vartok->link();

test/testsymboldatabase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ class TestSymbolDatabase : public TestFixture {
587587
TEST_CASE(valueType3);
588588
TEST_CASE(valueTypeThis);
589589
TEST_CASE(valueTypeChar);
590+
TEST_CASE(valueTypeRValueReference);
590591

591592
TEST_CASE(variadic1); // #7453
592593
TEST_CASE(variadic2); // #7649
@@ -10175,6 +10176,10 @@ class TestSymbolDatabase : public TestFixture {
1017510176
ASSERT_EQUALS("char", typeOf("char buf[10]; buf[0] = 'x';", "[ 0 ]", true, &s));
1017610177
}
1017710178

10179+
void valueTypeRValueReference() {
10180+
TODO_ASSERT_EQUALS("", "bool", typeOf("void f(std::string&& s = {})", "&&"));
10181+
}
10182+
1017810183
void variadic1() { // #7453
1017910184
{
1018010185
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,6 +5277,12 @@ class TestValueFlow : public TestFixture {
52775277
" continuous_src_time(std::complex<double> f, double st = 0.0, double et = infinity) {}\n"
52785278
"};";
52795279
(void)testValueOfX(code, 2U, 2); // Don't crash (#6494)
5280+
5281+
code = "struct S {\n" // #14693
5282+
" int i;\n"
5283+
" explicit S(std::string&& s = {}) : i(0) {}\n"
5284+
"};";
5285+
ASSERT_EQUALS(false, testKnownValueOfTok(code, "{ } )", 0));
52805286
}
52815287

52825288
bool isNotKnownValues(const char code[], const char str[]) {

0 commit comments

Comments
 (0)