Skip to content

Commit 922bf90

Browse files
committed
Add parens around template argument for cpp_new
1 parent a2efa20 commit 922bf90

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/cppconv/dwriter.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,7 +4933,14 @@ void parseTreeToDCode(T)(ref CodeWriter code, DWriterData data, T tree, immutabl
49334933
}
49344934
else
49354935
{
4936+
bool needsParens = !tree.childs[3].matchTreePattern!q{
4937+
NewTypeId([NameIdentifier | TypeKeyword], null)
4938+
};
4939+
if (needsParens)
4940+
code.write("(");
49364941
parseTreeToDCode(code, data, tree.childs[3], condition, currentScope);
4942+
if (needsParens)
4943+
code.write(")");
49374944
}
49384945
parseTreeToDCode(code, data, tree.childs[$ - 1], condition, currentScope);
49394946
}

tests/single/test371.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
template<typename T>
2+
class C
3+
{
4+
};
5+
6+
void f()
7+
{
8+
C<int> *c = new C<int>();
9+
10+
int *p = new int();
11+
}

tests/single/test371.d

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module test371;
2+
3+
import config;
4+
import cppconvhelpers;
5+
6+
extern(C++, class) struct C(T)
7+
{
8+
}
9+
10+
void f()
11+
{
12+
import core.stdcpp.new_;
13+
14+
C!(int)* c = cpp_new!(C!(int))();
15+
16+
int* p = cpp_new!int();
17+
}
18+

0 commit comments

Comments
 (0)