forked from qt-creator/qt-creator
C++11: Allow for brace initializers like T v{1, 2}.
And add a basic test. Change-Id: I3b8b87d51a9da154758d17380bba5922795f675c Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
6
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
6
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -2493,6 +2493,10 @@ bool Parser::parseInitDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_sp
|
||||
consumeToken();
|
||||
}
|
||||
|
||||
const bool isFunctionDeclarator = node
|
||||
&& node->postfix_declarator_list
|
||||
&& node->postfix_declarator_list->lastValue()
|
||||
&& node->postfix_declarator_list->lastValue()->asFunctionDeclarator();
|
||||
if (declaringClass && LA() == T_COLON
|
||||
&& (! node || ! node->postfix_declarator_list)) {
|
||||
unsigned colon_token = consumeToken();
|
||||
@@ -2506,7 +2510,7 @@ bool Parser::parseInitDeclarator(DeclaratorAST *&node, SpecifierListAST *decl_sp
|
||||
return true;
|
||||
}
|
||||
rewind(colon_token);
|
||||
} else if (node->core_declarator && (LA() == T_EQUAL || (! declaringClass && LA() == T_LPAREN))) {
|
||||
} else if (node->core_declarator && (LA() == T_EQUAL || (_cxx0xEnabled && !isFunctionDeclarator && LA() == T_LBRACE) || (! declaringClass && LA() == T_LPAREN))) {
|
||||
parseInitializer(node->initializer, &node->equal_token);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
include(../../qttest.pri)
|
||||
include(../shared/shared.pri)
|
||||
|
||||
DEFINES+=TESTSRCDIR=\\\"$$PWD\\\"
|
||||
|
||||
SOURCES += tst_cxx11.cpp
|
||||
OTHER_FILES += \
|
||||
data/inlineNamespace.1.cpp \
|
||||
|
||||
9
tests/auto/cplusplus/cxx11/data/braceInitializers.1.cpp
Normal file
9
tests/auto/cplusplus/cxx11/data/braceInitializers.1.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
Type var1 = { 1, 2, 3};
|
||||
Type var2{1, 2, 3};
|
||||
//Type var3({1, 2, 3});
|
||||
|
||||
class C {
|
||||
Type var1 = {1, 2, 3};
|
||||
Type var2{1, 2, 3};
|
||||
//Type var3({1, 2, 3});
|
||||
};
|
||||
@@ -44,7 +44,7 @@ using namespace CPlusPlus;
|
||||
QByteArray expectedErrors; \
|
||||
if (e.open(QFile::ReadOnly)) \
|
||||
expectedErrors = QTextStream(&e).readAll().toUtf8(); \
|
||||
QCOMPARE(errors, expectedErrors); \
|
||||
QCOMPARE(QString::fromLatin1(errors), QString::fromLatin1(expectedErrors)); \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ class tst_cxx11: public QObject
|
||||
*/
|
||||
static QString testdata(const QString &name = QString())
|
||||
{
|
||||
static const QString dataDirectory = QDir::currentPath() + QLatin1String("/data");
|
||||
static const QString dataDirectory = QLatin1String(TESTSRCDIR) + QLatin1String("/data");
|
||||
QString result = dataDirectory;
|
||||
if (!name.isEmpty()) {
|
||||
result += QLatin1Char('/');
|
||||
@@ -106,6 +106,8 @@ class tst_cxx11: public QObject
|
||||
doc->translationUnit()->setCxxOxEnabled(true);
|
||||
doc->check();
|
||||
doc->control()->setDiagnosticClient(0);
|
||||
} else {
|
||||
qWarning() << "could not read file" << fileName;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
@@ -114,12 +116,8 @@ private Q_SLOTS:
|
||||
//
|
||||
// checks for the syntax
|
||||
//
|
||||
void inlineNamespace_data();
|
||||
void inlineNamespace();
|
||||
void staticAssert();
|
||||
void staticAssert_data();
|
||||
void noExcept();
|
||||
void noExcept_data();
|
||||
void parse_data();
|
||||
void parse();
|
||||
|
||||
//
|
||||
// checks for the semantic
|
||||
@@ -128,15 +126,18 @@ private Q_SLOTS:
|
||||
};
|
||||
|
||||
|
||||
void tst_cxx11::inlineNamespace_data()
|
||||
void tst_cxx11::parse_data()
|
||||
{
|
||||
QTest::addColumn<QString>("file");
|
||||
QTest::addColumn<QString>("errorFile");
|
||||
|
||||
QTest::newRow("inlineNamespace.1") << "inlineNamespace.1.cpp" << "inlineNamespace.1.errors.txt";
|
||||
QTest::newRow("staticAssert.1") << "staticAssert.1.cpp" << "staticAssert.1.errors.txt";
|
||||
QTest::newRow("noExcept.1") << "noExcept.1.cpp" << "noExcept.1.errors.txt";
|
||||
QTest::newRow("braceInitializers.1") << "braceInitializers.1.cpp" << "braceInitializers.1.errors.txt";
|
||||
}
|
||||
|
||||
void tst_cxx11::inlineNamespace()
|
||||
void tst_cxx11::parse()
|
||||
{
|
||||
QFETCH(QString, file);
|
||||
QFETCH(QString, errorFile);
|
||||
@@ -166,49 +167,5 @@ void tst_cxx11::inlineNamespaceLookup()
|
||||
QCOMPARE(results.size(), 1); // the symbol is visible from the global scope
|
||||
}
|
||||
|
||||
void tst_cxx11::staticAssert_data()
|
||||
{
|
||||
QTest::addColumn<QString>("file");
|
||||
QTest::addColumn<QString>("errorFile");
|
||||
|
||||
QTest::newRow("staticAssert.1") << "staticAssert.1.cpp" << "staticAssert.1.errors.txt";
|
||||
}
|
||||
|
||||
void tst_cxx11::staticAssert()
|
||||
{
|
||||
QFETCH(QString, file);
|
||||
QFETCH(QString, errorFile);
|
||||
|
||||
QByteArray errors;
|
||||
Document::Ptr doc = document(file, &errors);
|
||||
|
||||
if (! qgetenv("DEBUG").isNull())
|
||||
printf("%s\n", errors.constData());
|
||||
|
||||
VERIFY_ERRORS();
|
||||
}
|
||||
|
||||
void tst_cxx11::noExcept_data()
|
||||
{
|
||||
QTest::addColumn<QString>("file");
|
||||
QTest::addColumn<QString>("errorFile");
|
||||
|
||||
QTest::newRow("noExcept.1") << "noExcept.1.cpp" << "noExcept.1.errors.txt";
|
||||
}
|
||||
|
||||
void tst_cxx11::noExcept()
|
||||
{
|
||||
QFETCH(QString, file);
|
||||
QFETCH(QString, errorFile);
|
||||
|
||||
QByteArray errors;
|
||||
Document::Ptr doc = document(file, &errors);
|
||||
|
||||
if (! qgetenv("DEBUG").isNull())
|
||||
printf("%s\n", errors.constData());
|
||||
|
||||
VERIFY_ERRORS();
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(tst_cxx11)
|
||||
#include "tst_cxx11.moc"
|
||||
|
||||
Reference in New Issue
Block a user