forked from qt-creator/qt-creator
C++: Fix accessing invalid file id of Symbol
Symbol::_fileId can be null if the Symbol was created with a null translation unit. That is the case for temporary symbols created for lookup purposes (CreateBindings has a _control with no translation unit and thus creates symbols with no fileId). Task-number: QTCREATORBUG-15967 Change-Id: Iee518b39ba3b636fe1658e74179db3aad054d6f2 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
4
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
4
src/libs/3rdparty/cplusplus/Symbol.cpp
vendored
@@ -191,10 +191,10 @@ const StringLiteral *Symbol::fileId() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *Symbol::fileName() const
|
const char *Symbol::fileName() const
|
||||||
{ return fileId()->chars(); }
|
{ return _fileId ? _fileId->chars() : ""; }
|
||||||
|
|
||||||
unsigned Symbol::fileNameLength() const
|
unsigned Symbol::fileNameLength() const
|
||||||
{ return fileId()->size(); }
|
{ return _fileId ? _fileId->size() : 0; }
|
||||||
|
|
||||||
const Name *Symbol::unqualifiedName() const
|
const Name *Symbol::unqualifiedName() const
|
||||||
{
|
{
|
||||||
|
@@ -219,6 +219,8 @@ private slots:
|
|||||||
void test_checksymbols_infiniteLoop_data();
|
void test_checksymbols_infiniteLoop_data();
|
||||||
void test_checksymbols_infiniteLoop();
|
void test_checksymbols_infiniteLoop();
|
||||||
|
|
||||||
|
void test_checkForValidSymbolFileId();
|
||||||
|
|
||||||
void test_parentOfBlock();
|
void test_parentOfBlock();
|
||||||
|
|
||||||
void findField();
|
void findField();
|
||||||
@@ -1165,6 +1167,33 @@ void tst_CheckSymbols::test_checksymbols_infiniteLoop()
|
|||||||
TestCase::runCheckSymbols(document1, snapshot);
|
TestCase::runCheckSymbols(document1, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_CheckSymbols::test_checkForValidSymbolFileId()
|
||||||
|
{
|
||||||
|
const QByteArray contents =
|
||||||
|
"constexpr int parent_of(const int f) { return 1; }\n"
|
||||||
|
"\n"
|
||||||
|
"template <typename T> struct wrapper { const T* ptr; };\n"
|
||||||
|
"template <int> struct Dummy;\n"
|
||||||
|
"\n"
|
||||||
|
"namespace impl {\n"
|
||||||
|
" template <int f>\n"
|
||||||
|
" struct dummy_impl {\n"
|
||||||
|
" wrapper<Dummy<parent_of(f)>> parent;\n"
|
||||||
|
" };\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"template <int f>\n"
|
||||||
|
"struct Dummy : impl::dummy_impl<f> {};\n"
|
||||||
|
"\n"
|
||||||
|
"void client()\n"
|
||||||
|
"{\n"
|
||||||
|
" wrapper<Dummy<1>> a;\n"
|
||||||
|
" a.ptr->parent.ptr;\n"
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
BaseTestCase tc(contents);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_CheckSymbols::test_parentOfBlock()
|
void tst_CheckSymbols::test_parentOfBlock()
|
||||||
{
|
{
|
||||||
const QByteArray source = "void C::f()\n"
|
const QByteArray source = "void C::f()\n"
|
||||||
|
Reference in New Issue
Block a user