Details
-
Bug
-
Resolution: Incomplete
-
P3: Somewhat important
-
None
-
Qt Creator 3.5.0-beta1, Qt Creator 3.5.0-rc1
-
None
-
Linux: Ubuntu 14.04
Windows: Win 7
Description
As the subject states, CPlusPlus::TranslationUnit::getTokenStartPosition() returns wrong position for QStringLiteral() on Windows. On Linux the correct position is returned.
The following code samples can be used to replicate the issue:
Adding the following code to a file "teststringliteral.cpp" and add the file to a small test project that will be opened with the QtCreator under test:
#include <QString> void test() { QStringLiteral("Test String Literal"); QString test = QStringLiteral("Test String Literal"); }
The following code can be added inside the QtCreator under test
connect(CppTools::CppModelManager::instance(), &CppTools::CppModelManager::documentUpdated, this, [](CPlusPlus::Document::Ptr doc){ if(doc->fileName().endsWith(QStringLiteral("testqstringliteral.cpp")) == false) { return; } qDebug() << "Starting to parse file..."; CPlusPlus::TranslationUnit *trUnit = doc->translationUnit(); unsigned int tokenCount = trUnit->tokenCount(); for(unsigned int idx = 0; idx < tokenCount; ++idx) { const CPlusPlus::Token& token = trUnit->tokenAt(idx); if(token.isStringLiteral() == true) { if(token.expanded() == true) { unsigned line, column; trUnit->getTokenStartPosition(idx, &line, &column); qDebug().nospace() << "String: \"" << token.spell() << "\" at line: " << line << " column: " << column; continue; } } } }, Qt::DirectConnection);
The output on Linux (Qt 5.4 gcc 4.8.2):
Starting to parse file... String: "" at line: 5 column: 19 String: "Test String Literal" at line: 4 column: 20 String: "" at line: 5 column: 44 String: "Test String Literal" at line: 4 column: 20 String: "" at line: 7 column: 19 String: "Test String Literal" at line: 5 column: 35 String: "" at line: 7 column: 44 String: "Test String Literal" at line: 5 column: 35
On Windows (Qt 5.4 msvc2013):
Starting to parse file... String: "Test String Literal" at line: 5 column: 41 String: "Test String Literal" at line: 5 column: 182 String: "Test String Literal" at line: 7 column: 41 String: "Test String Literal" at line: 7 column: 182
One can clearly see that on windows the Line and Column gets reported incorrectly, compared to Linux where it is correct.
I hope the information supplied is enough, if not please indicate any better way that I can provide the information in.
Regards