SymbolDatabase: Fix valuetype with constexpr and auto (#3577)
This commit is contained in:
parent
a6b8339990
commit
085d25f1b1
|
@ -5817,9 +5817,9 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
Token::Match(parent->tokAt(-1), "%var% ="))) {
|
Token::Match(parent->tokAt(-1), "%var% ="))) {
|
||||||
Token *var1Tok = parent->strAt(-2) == ";" ? parent->tokAt(-3) : parent->tokAt(-1);
|
Token *var1Tok = parent->strAt(-2) == ";" ? parent->tokAt(-3) : parent->tokAt(-1);
|
||||||
Token *autoTok = nullptr;
|
Token *autoTok = nullptr;
|
||||||
if (Token::Match(var1Tok->tokAt(-2), ";|{|}|(|const auto"))
|
if (Token::Match(var1Tok->tokAt(-2), ";|{|}|(|const|constexpr auto"))
|
||||||
autoTok = var1Tok->previous();
|
autoTok = var1Tok->previous();
|
||||||
else if (Token::Match(var1Tok->tokAt(-3), ";|{|}|(|const auto *"))
|
else if (Token::Match(var1Tok->tokAt(-3), ";|{|}|(|const|constexpr auto *"))
|
||||||
autoTok = var1Tok->tokAt(-2);
|
autoTok = var1Tok->tokAt(-2);
|
||||||
if (autoTok) {
|
if (autoTok) {
|
||||||
ValueType vt(*vt2);
|
ValueType vt(*vt2);
|
||||||
|
@ -5827,7 +5827,7 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
|
||||||
vt.constness &= ~(1 << vt.pointer);
|
vt.constness &= ~(1 << vt.pointer);
|
||||||
if (autoTok->strAt(1) == "*" && vt.pointer)
|
if (autoTok->strAt(1) == "*" && vt.pointer)
|
||||||
vt.pointer--;
|
vt.pointer--;
|
||||||
if (autoTok->strAt(-1) == "const")
|
if (Token::Match(autoTok->tokAt(-1), "const|constexpr"))
|
||||||
vt.constness |= 1;
|
vt.constness |= 1;
|
||||||
setValueType(autoTok, vt);
|
setValueType(autoTok, vt);
|
||||||
setAutoTokenProperties(autoTok);
|
setAutoTokenProperties(autoTok);
|
||||||
|
|
|
@ -6415,6 +6415,14 @@ private:
|
||||||
" return i >= 0;\n"
|
" return i >= 0;\n"
|
||||||
"}\n", &settings1);
|
"}\n", &settings1);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #10612
|
||||||
|
check("void f(void) {\n"
|
||||||
|
" const uint32_t x = 0;\n"
|
||||||
|
" constexpr const auto y = 0xFFFFU;\n"
|
||||||
|
" if (y < x) {}\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:4]: (style) Checking if unsigned expression 'y' is less than zero.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkSignOfPointer() {
|
void checkSignOfPointer() {
|
||||||
|
|
|
@ -7543,12 +7543,21 @@ private:
|
||||||
// auto variables
|
// auto variables
|
||||||
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
|
ASSERT_EQUALS("signed int", typeOf("; auto x = 3;", "x"));
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
|
ASSERT_EQUALS("signed int *", typeOf("; auto *p = (int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; auto *p = (const int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; auto *p = (constexpr int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; const auto *p = (int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; constexpr auto *p = (int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; const auto *p = (const int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; constexpr auto *p = (constexpr int *)0;", "p"));
|
||||||
|
ASSERT_EQUALS("const signed int *", typeOf("; const constexpr auto *p = (int *)0;", "p"));
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto data = new int[100];", "data"));
|
ASSERT_EQUALS("signed int *", typeOf("; auto data = new int[100];", "data"));
|
||||||
ASSERT_EQUALS("signed int", typeOf("; auto data = new X::Y; int x=1000; x=x/5;", "/")); // #7970
|
ASSERT_EQUALS("signed int", typeOf("; auto data = new X::Y; int x=1000; x=x/5;", "/")); // #7970
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (nothrow) int[100];", "data"));
|
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (nothrow) int[100];", "data"));
|
||||||
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
|
ASSERT_EQUALS("signed int *", typeOf("; auto data = new (std::nothrow) int[100];", "data"));
|
||||||
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
|
ASSERT_EQUALS("const signed short", typeOf("short values[10]; void f() { for (const auto *x : values); }", "x"));
|
||||||
ASSERT_EQUALS("const signed int", typeOf("; const auto x = 3;", "x"));
|
ASSERT_EQUALS("const signed int", typeOf("; const auto x = 3;", "x"));
|
||||||
|
ASSERT_EQUALS("const signed int", typeOf("; constexpr auto x = 3;", "x"));
|
||||||
|
ASSERT_EQUALS("const signed int", typeOf("; const constexpr auto x = 3;", "x"));
|
||||||
|
|
||||||
// Variable declaration
|
// Variable declaration
|
||||||
ASSERT_EQUALS("char *", typeOf("; char abc[] = \"abc\";", "["));
|
ASSERT_EQUALS("char *", typeOf("; char abc[] = \"abc\";", "["));
|
||||||
|
|
Loading…
Reference in New Issue