Skip to content

Commit c7154b0

Browse files
committed
Fix an error introduced in llvm#138518
1 parent 3b9ebe9 commit c7154b0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,11 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
21602160
"paren init for non-call init");
21612161
Exprs = MultiExprArg(List->getExprs(), List->getNumExprs());
21622162
}
2163+
if (auto *List = dyn_cast_or_null<CXXParenListInitExpr>(Initializer)) {
2164+
assert(InitStyle == CXXNewInitializationStyle::Parens &&
2165+
"paren init for non-call init");
2166+
Exprs = List->getInitExprs();
2167+
}
21632168

21642169
// C++11 [expr.new]p15:
21652170
// A new-expression that creates an object of type T initializes that
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump %s | FileCheck %s
2+
struct Node {
3+
long val;
4+
};
5+
template <bool>
6+
void CallNew() {
7+
new Node(0);
8+
}
9+
// CHECK-LABEL: FunctionTemplateDecl {{.*}} CallNew
10+
// CHECK: |-FunctionDecl {{.*}} CallNew 'void ()'
11+
// CHECK: `-CXXNewExpr {{.*}} 'operator new' 'void *(unsigned long)'
12+
// CHECK: `-CXXParenListInitExpr {{.*}} 'Node'
13+
// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast>
14+
// CHECK: `-IntegerLiteral {{.*}} 'int' 0
15+
// CHECK: `-FunctionDecl {{.*}} used CallNew 'void ()' implicit_instantiation
16+
// CHECK: |-TemplateArgument integral 'true'
17+
// CHECK: `-CXXNewExpr {{.*}} 'operator new' 'void *(unsigned long)'
18+
// CHECK: `-CXXParenListInitExpr {{.*}} 'Node'
19+
// CHECK: `-ImplicitCastExpr {{.*}} 'long' <IntegralCast>
20+
// CHECK: `-IntegerLiteral {{.*}} 'int' 0
21+
void f() {
22+
(void)CallNew<true>;
23+
}

0 commit comments

Comments
 (0)