forked from qt-creator/qt-creator
Add support for nested namespaces (C++17)
Task-number: QTCREATORBUG-16774 Change-Id: I3de3ac65810213e21c9a3bafef2474d252e191f7 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
23
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
23
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -863,7 +863,8 @@ bool Parser::parseStaticAssertDeclaration(DeclarationAST *&node)
|
||||
bool Parser::parseNamespace(DeclarationAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
if (LA() != T_NAMESPACE && !(_languageFeatures.cxx11Enabled && LA() == T_INLINE && LA(2) == T_NAMESPACE))
|
||||
if (LA() != T_NAMESPACE && !(_languageFeatures.cxx11Enabled && LA() == T_INLINE && LA(2) == T_NAMESPACE)
|
||||
&& !isNestedNamespace())
|
||||
return false;
|
||||
|
||||
unsigned inline_token = 0;
|
||||
@@ -892,7 +893,9 @@ bool Parser::parseNamespace(DeclarationAST *&node)
|
||||
if (LA() == T_IDENTIFIER)
|
||||
ast->identifier_token = consumeToken();
|
||||
parseOptionalAttributeSpecifierSequence(ast->attribute_list);
|
||||
if (LA() == T_LBRACE) {
|
||||
if (isNestedNamespace()) {
|
||||
parseNestedNamespace(ast->linkage_body);
|
||||
} else if (LA() == T_LBRACE) {
|
||||
parseLinkageBody(ast->linkage_body);
|
||||
} else { // attempt to do error recovery
|
||||
unsigned pos = cursor();
|
||||
@@ -923,6 +926,22 @@ bool Parser::parseNamespace(DeclarationAST *&node)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::isNestedNamespace() const
|
||||
{
|
||||
return _languageFeatures.cxx11Enabled && LA() == T_COLON_COLON && LA(2) == T_IDENTIFIER;
|
||||
}
|
||||
|
||||
bool Parser::parseNestedNamespace(DeclarationAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
DeclarationAST *ast = 0;
|
||||
if (isNestedNamespace() && parseNamespace(ast)) {
|
||||
node = ast;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Parser::parseUsing(DeclarationAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
|
3
src/libs/3rdparty/cplusplus/Parser.h
vendored
3
src/libs/3rdparty/cplusplus/Parser.h
vendored
@@ -119,6 +119,7 @@ public:
|
||||
bool parseNestedNameSpecifierOpt(NestedNameSpecifierListAST *&name, bool acceptTemplateId);
|
||||
bool parseStaticAssertDeclaration(DeclarationAST *&node);
|
||||
bool parseNamespace(DeclarationAST *&node);
|
||||
bool parseNestedNamespace(DeclarationAST *&node);
|
||||
bool parseNamespaceAliasDefinition(DeclarationAST *&node);
|
||||
bool parseNewArrayDeclarator(NewArrayDeclaratorListAST *&node);
|
||||
bool parseNewExpression(ExpressionAST *&node);
|
||||
@@ -332,6 +333,8 @@ private:
|
||||
private:
|
||||
Parser(const Parser& source);
|
||||
void operator =(const Parser& source);
|
||||
|
||||
bool isNestedNamespace() const;
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
@@ -7,6 +7,8 @@ SOURCES += tst_cxx11.cpp
|
||||
DISTFILES += \
|
||||
data/inlineNamespace.1.cpp \
|
||||
data/inlineNamespace.1.errors.txt \
|
||||
data/nestedNamespace.1.cpp \
|
||||
data/nestedNamespace.1.errors.txt \
|
||||
data/staticAssert.1.cpp \
|
||||
data/staticAssert.1.errors.txt \
|
||||
data/noExcept.1.cpp \
|
||||
|
7
tests/auto/cplusplus/cxx11/data/nestedNamespace.1.cpp
Normal file
7
tests/auto/cplusplus/cxx11/data/nestedNamespace.1.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
namespace A::B::C {
|
||||
class Foo {
|
||||
|
||||
};
|
||||
}
|
||||
|
@@ -176,6 +176,7 @@ void tst_cxx11::parse_data()
|
||||
QTest::addColumn<QString>("errorFile");
|
||||
|
||||
QTest::newRow("inlineNamespace.1") << "inlineNamespace.1.cpp" << "inlineNamespace.1.errors.txt";
|
||||
QTest::newRow("nestedNamespace.1") << "nestedNamespace.1.cpp" << "nestedNamespace.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";
|
||||
|
Reference in New Issue
Block a user