forked from qt-creator/qt-creator
CppEditor: Fix "insert definition" for templates with value parameters
Fixes: QTCREATORBUG-26113 Change-Id: I2d2a1c1bdcffd67072bbda99dabbbfbfafe115c5 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
1
src/libs/3rdparty/cplusplus/Names.h
vendored
1
src/libs/3rdparty/cplusplus/Names.h
vendored
@@ -95,6 +95,7 @@ public:
|
|||||||
FullySpecifiedType &type() { return _expressionTy; }
|
FullySpecifiedType &type() { return _expressionTy; }
|
||||||
|
|
||||||
const NumericLiteral *numericLiteral() const { return _numericLiteral; }
|
const NumericLiteral *numericLiteral() const { return _numericLiteral; }
|
||||||
|
void setNumericLiteral(const NumericLiteral *l) { _numericLiteral = l; }
|
||||||
|
|
||||||
bool operator==(const TemplateArgument &other) const
|
bool operator==(const TemplateArgument &other) const
|
||||||
{
|
{
|
||||||
|
5
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
5
src/libs/3rdparty/cplusplus/Templates.cpp
vendored
@@ -440,8 +440,11 @@ void CloneName::visit(const AnonymousNameId *name)
|
|||||||
void CloneName::visit(const TemplateNameId *name)
|
void CloneName::visit(const TemplateNameId *name)
|
||||||
{
|
{
|
||||||
std::vector<TemplateArgument> args(name->templateArgumentCount());
|
std::vector<TemplateArgument> 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].type() = _clone->type(name->templateArgumentAt(i).type(), _subst);
|
||||||
|
args[i].setNumericLiteral(_clone->numericLiteral(
|
||||||
|
name->templateArgumentAt(i).numericLiteral()));
|
||||||
|
}
|
||||||
if (args.empty())
|
if (args.empty())
|
||||||
_name = _control->templateNameId(_clone->identifier(name->identifier()), name->isSpecialization());
|
_name = _control->templateNameId(_clone->identifier(name->identifier()), name->isSpecialization());
|
||||||
else
|
else
|
||||||
|
@@ -274,8 +274,15 @@ public:
|
|||||||
void visit(const TemplateNameId *name) override
|
void visit(const TemplateNameId *name) override
|
||||||
{
|
{
|
||||||
QVarLengthArray<TemplateArgument, 8> args(name->templateArgumentCount());
|
QVarLengthArray<TemplateArgument, 8> args(name->templateArgumentCount());
|
||||||
for (int i = 0; i < name->templateArgumentCount(); ++i)
|
for (int i = 0; i < name->templateArgumentCount(); ++i) {
|
||||||
args[i] = rewrite->rewriteType(name->templateArgumentAt(i).type());
|
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(),
|
temps.append(control()->templateNameId(identifier(name->identifier()), name->isSpecialization(),
|
||||||
args.data(), args.size()));
|
args.data(), args.size()));
|
||||||
}
|
}
|
||||||
|
@@ -169,6 +169,7 @@ private slots:
|
|||||||
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
||||||
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
||||||
void test_quickfix_InsertDefFromDecl_templateClass();
|
void test_quickfix_InsertDefFromDecl_templateClass();
|
||||||
|
void test_quickfix_InsertDefFromDecl_templateClassWithValueParam();
|
||||||
void test_quickfix_InsertDefFromDecl_templateFunction();
|
void test_quickfix_InsertDefFromDecl_templateFunction();
|
||||||
void test_quickfix_InsertDefFromDecl_notTriggeredForFriendFunc();
|
void test_quickfix_InsertDefFromDecl_notTriggeredForFriendFunc();
|
||||||
void test_quickfix_InsertDefFromDecl_minimalFunctionParameterType();
|
void test_quickfix_InsertDefFromDecl_minimalFunctionParameterType();
|
||||||
|
@@ -4605,6 +4605,27 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateClass()
|
|||||||
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
QuickFixOperationTest(singleDocument(original, expected), &factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateClassWithValueParam()
|
||||||
|
{
|
||||||
|
QList<QuickFixTestDocument::Ptr> testDocuments;
|
||||||
|
QByteArray original =
|
||||||
|
"template<typename T, int size> struct MyArray {};\n"
|
||||||
|
"MyArray<int, 1> @foo();";
|
||||||
|
QByteArray expected = original;
|
||||||
|
testDocuments << QuickFixTestDocument::create("file.h", original, expected);
|
||||||
|
|
||||||
|
original = "#include \"file.h\"\n";
|
||||||
|
expected =
|
||||||
|
"#include \"file.h\"\n\n"
|
||||||
|
"MyArray<int, 1> foo()\n"
|
||||||
|
"{\n\n"
|
||||||
|
"}\n";
|
||||||
|
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||||
|
|
||||||
|
InsertDefFromDecl factory;
|
||||||
|
QuickFixOperationTest(testDocuments, &factory);
|
||||||
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateFunction()
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_templateFunction()
|
||||||
{
|
{
|
||||||
QByteArray original =
|
QByteArray original =
|
||||||
|
Reference in New Issue
Block a user