[cfe-dev] Strange New Arrays
Uri Mann via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 14 05:49:33 PST 2015
I'm using CALNG 3.7.0. I have the following visitor class:
class MyVisitor : public clang::RecursiveASTVisitor<MyVisitor> {
public:
bool VisitCXXNewExpr(clang::CXXNewExpr* cxxNewExpr) { cxxNewExpr->dumpColor(); }
};
Parsing and visiting the code:
int* p;
p = new int[5]{1, 2, 3, 4, 5};
p = new int[]{1, 2, 3, 4, 5};
I see to two unexplained behaviors.
1. CLANG error
source.cpp(56,17) : error: expected expression
p = new int[]{1, 2, 3, 4, 5};
^
source.cpp(56,13) : error: excess elements in
scalar initializer
p = new int[]{1, 2, 3, 4, 5};
^
2. The dump shows 6 element array
CXXNewExpr 0x1f0f9c0 'int *' array Function 0x1eea460 'operator new[]' 'void *(unsigned long)'
|-IntegerLiteral 0x1f0f748 'int' 5
`-InitListExpr 0x1f0f8f8 'int [6]'
|-array filler
| `-ImplicitValueInitExpr 0x1f0f9b0 'int'
|-IntegerLiteral 0x1f0f770 'int' 1
|-IntegerLiteral 0x1f0f798 'int' 2
|-IntegerLiteral 0x1f0f7c0 'int' 3
|-IntegerLiteral 0x1f0f7e8 'int' 4
`-IntegerLiteral 0x1f0f810 'int' 5
a) Is implicit array sizing using initializer-list ilegal in new expression?
b) Why would the first array more than 5 elements?
Many thanks in advance.
-Uri
More information about the cfe-dev
mailing list