diff --git a/src/libs/3rdparty/cplusplus/Names.h b/src/libs/3rdparty/cplusplus/Names.h index 7e65e4c74c5..5b915bdfb4e 100644 --- a/src/libs/3rdparty/cplusplus/Names.h +++ b/src/libs/3rdparty/cplusplus/Names.h @@ -95,6 +95,7 @@ public: FullySpecifiedType &type() { return _expressionTy; } const NumericLiteral *numericLiteral() const { return _numericLiteral; } + void setNumericLiteral(const NumericLiteral *l) { _numericLiteral = l; } bool operator==(const TemplateArgument &other) const { diff --git a/src/libs/3rdparty/cplusplus/Templates.cpp b/src/libs/3rdparty/cplusplus/Templates.cpp index 92e5ab14fc3..4a222e03633 100644 --- a/src/libs/3rdparty/cplusplus/Templates.cpp +++ b/src/libs/3rdparty/cplusplus/Templates.cpp @@ -440,8 +440,11 @@ void CloneName::visit(const AnonymousNameId *name) void CloneName::visit(const TemplateNameId *name) { std::vector args(name->templateArgumentCount()); - for (int i = 0; i < int(args.size()); ++i) + for (int i = 0; i < int(args.size()); ++i) { args[i].type() = _clone->type(name->templateArgumentAt(i).type(), _subst); + args[i].setNumericLiteral(_clone->numericLiteral( + name->templateArgumentAt(i).numericLiteral())); + } if (args.empty()) _name = _control->templateNameId(_clone->identifier(name->identifier()), name->isSpecialization()); else diff --git a/src/libs/cplusplus/CppRewriter.cpp b/src/libs/cplusplus/CppRewriter.cpp index 174004fbfff..ac5b763aec7 100644 --- a/src/libs/cplusplus/CppRewriter.cpp +++ b/src/libs/cplusplus/CppRewriter.cpp @@ -274,8 +274,15 @@ public: void visit(const TemplateNameId *name) override { QVarLengthArray args(name->templateArgumentCount()); - for (int i = 0; i < name->templateArgumentCount(); ++i) - args[i] = rewrite->rewriteType(name->templateArgumentAt(i).type()); + for (int i = 0; i < name->templateArgumentCount(); ++i) { + const TemplateArgument &oldArg = name->templateArgumentAt(i); + args[i] = rewrite->rewriteType(oldArg.type()); + const NumericLiteral * const number = oldArg.numericLiteral(); + if (number) { + args[i].setNumericLiteral(control()->numericLiteral(number->chars(), + number->size())); + } + } temps.append(control()->templateNameId(identifier(name->identifier()), name->isSpecialization(), args.data(), args.size())); } diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 5bb1abc9cb2..969cd002f12 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -169,6 +169,7 @@ private slots: void test_quickfix_InsertDefFromDecl_findImplementationFile(); void test_quickfix_InsertDefFromDecl_unicodeIdentifier(); void test_quickfix_InsertDefFromDecl_templateClass(); + void test_quickfix_InsertDefFromDecl_templateClassWithValueParam(); void test_quickfix_InsertDefFromDecl_templateFunction(); void test_quickfix_InsertDefFromDecl_notTriggeredForFriendFunc(); void test_quickfix_InsertDefFromDecl_minimalFunctionParameterType(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index da0c8a944eb..542c4972bb1 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -4605,6 +4605,27 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateClass() QuickFixOperationTest(singleDocument(original, expected), &factory); } +void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateClassWithValueParam() +{ + QList testDocuments; + QByteArray original = + "template struct MyArray {};\n" + "MyArray @foo();"; + QByteArray expected = original; + testDocuments << QuickFixTestDocument::create("file.h", original, expected); + + original = "#include \"file.h\"\n"; + expected = + "#include \"file.h\"\n\n" + "MyArray foo()\n" + "{\n\n" + "}\n"; + testDocuments << QuickFixTestDocument::create("file.cpp", original, expected); + + InsertDefFromDecl factory; + QuickFixOperationTest(testDocuments, &factory); +} + void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateFunction() { QByteArray original =