mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 05:36:06 +00:00
[Clang] Remove redundant init-parens in AST print
Given a dependent `T` (maybe an undeduced `auto`), Before: new T(z) --> new T((z)) # changes meaning with more args new T{z} --> new T{z} T(z) --> T(z) T{z} --> T({z}) # forbidden if T is auto After: new T(z) --> new T(z) new T{z} --> new T{z} T(z) --> T(z) T{z} --> T{z} Depends on D113393 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D120608
This commit is contained in:
parent
136b293129
commit
d1a59eefd3
@ -2153,11 +2153,13 @@ void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
|
||||
OS << ")";
|
||||
|
||||
CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
|
||||
if (InitStyle) {
|
||||
if (InitStyle == CXXNewExpr::CallInit)
|
||||
if (InitStyle != CXXNewExpr::NoInit) {
|
||||
bool Bare = InitStyle == CXXNewExpr::CallInit &&
|
||||
!isa<ParenListExpr>(E->getInitializer());
|
||||
if (Bare)
|
||||
OS << "(";
|
||||
PrintExpr(E->getInitializer());
|
||||
if (InitStyle == CXXNewExpr::CallInit)
|
||||
if (Bare)
|
||||
OS << ")";
|
||||
}
|
||||
}
|
||||
@ -2219,19 +2221,19 @@ void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
|
||||
PrintExpr(E->getSubExpr());
|
||||
}
|
||||
|
||||
void
|
||||
StmtPrinter::VisitCXXUnresolvedConstructExpr(
|
||||
CXXUnresolvedConstructExpr *Node) {
|
||||
void StmtPrinter::VisitCXXUnresolvedConstructExpr(
|
||||
CXXUnresolvedConstructExpr *Node) {
|
||||
Node->getTypeAsWritten().print(OS, Policy);
|
||||
OS << "(";
|
||||
for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
|
||||
ArgEnd = Node->arg_end();
|
||||
Arg != ArgEnd; ++Arg) {
|
||||
if (!Node->isListInitialization())
|
||||
OS << '(';
|
||||
for (auto Arg = Node->arg_begin(), ArgEnd = Node->arg_end(); Arg != ArgEnd;
|
||||
++Arg) {
|
||||
if (Arg != Node->arg_begin())
|
||||
OS << ", ";
|
||||
PrintExpr(*Arg);
|
||||
}
|
||||
OS << ")";
|
||||
if (!Node->isListInitialization())
|
||||
OS << ')';
|
||||
}
|
||||
|
||||
void StmtPrinter::VisitCXXDependentScopeMemberExpr(
|
||||
|
@ -72,7 +72,7 @@ struct E {
|
||||
};
|
||||
|
||||
template<typename T> requires requires(T t) { typename E<T>::non_default_constructible{}; }
|
||||
// expected-note@-1 {{because 'typename E<T>::non_default_constructible({})' would be invalid: no matching constructor for initialization of 'typename E<int>::non_default_constructible'}}
|
||||
// expected-note@-1 {{because 'typename E<T>::non_default_constructible{}' would be invalid: no matching constructor for initialization of 'typename E<int>::non_default_constructible'}}
|
||||
struct r6 {};
|
||||
|
||||
using r6i1 = r6<int>;
|
||||
|
@ -1,5 +1,6 @@
|
||||
// RUN: %clang_cc1 -std=c++2b -fsyntax-only -ast-print %s | FileCheck %s
|
||||
|
||||
template <template <class...> class C>
|
||||
void test_auto_expr(long long y, auto &&z) {
|
||||
int x[] = {3, 4};
|
||||
|
||||
@ -15,16 +16,36 @@ void test_auto_expr(long long y, auto &&z) {
|
||||
|
||||
// CHECK{LITERAL}: auto(z)
|
||||
void(auto(z));
|
||||
// CHECK{LITERAL}: auto({z})
|
||||
void(auto{z}); // T({z}) is legal unless T = auto
|
||||
// CHECK{LITERAL}: auto{z}
|
||||
void(auto{z});
|
||||
|
||||
// CHECK{LITERAL}: new int *(x)
|
||||
void(new auto(x));
|
||||
// CHECK{LITERAL}: new int *{x}
|
||||
void(new auto{x});
|
||||
|
||||
// CHECK{LITERAL}: new auto(z)
|
||||
void(new auto(z));
|
||||
// CHECK{LITERAL}: new auto{z}
|
||||
void(new auto{z});
|
||||
|
||||
// CHECK{LITERAL}: new long long(y)
|
||||
void(new decltype(auto)(y));
|
||||
// CHECK{LITERAL}: new long long{y}
|
||||
void(new decltype(auto){y});
|
||||
|
||||
// CHECK{LITERAL}: new decltype(auto)(z)
|
||||
void(new decltype(auto)(z));
|
||||
// CHECK{LITERAL}: new decltype(auto){z}
|
||||
void(new decltype(auto){z});
|
||||
|
||||
// CHECK{LITERAL}: C(x, y, z)
|
||||
void(C(x, y, z));
|
||||
// CHECK{LITERAL}: C{x, y, z}
|
||||
void(C{x, y, z});
|
||||
|
||||
// CHECK{LITERAL}: new C(x, y, z)
|
||||
void(new C(x, y, z));
|
||||
// CHECK{LITERAL}: new C{x, y, z}
|
||||
void(new C{x, y, z});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user