summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-02-25 17:26:26 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-02-25 17:26:26 +0000
commit48f52e926d6e8273587f5befc997fc784b04855b (patch)
tree7bb39b8f7dfcf67771391b649b7f19e27101d503
parenta3283443675143ad384cdab710b1c04945f9f368 (diff)
downloadbcm5719-llvm-48f52e926d6e8273587f5befc997fc784b04855b.tar.gz
bcm5719-llvm-48f52e926d6e8273587f5befc997fc784b04855b.zip
Pretty Printer: Fix printing of conversion operator decls and calls.
- Don't emit anything when we encounter a call to a conversion operator. "bar(a & b)" instead of "bar(a & b.operator int())" This preserves the semantics and is still idempotent if we print the AST multiple times. - Properly print declarations of conversion operators. "explicit operator bool();" instead of "bool operator _Bool();" PR18776. llvm-svn: 202167
-rw-r--r--clang/lib/AST/DeclPrinter.cpp10
-rw-r--r--clang/lib/AST/DeclarationName.cpp2
-rw-r--r--clang/lib/AST/StmtPrinter.cpp6
-rw-r--r--clang/test/SemaCXX/ast-print.cpp25
4 files changed, 38 insertions, 5 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index aa753887a21..05701a5b061 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -385,6 +385,7 @@ void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
+ CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
if (!Policy.SuppressSpecifiers) {
switch (D->getStorageClass()) {
case SC_None: break;
@@ -398,7 +399,8 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
if (D->isInlineSpecified()) Out << "inline ";
if (D->isVirtualAsWritten()) Out << "virtual ";
if (D->isModulePrivate()) Out << "__module_private__ ";
- if (CDecl && CDecl->isExplicitSpecified())
+ if ((CDecl && CDecl->isExplicitSpecified()) ||
+ (ConversionDecl && ConversionDecl->isExplicit()))
Out << "explicit ";
}
@@ -536,15 +538,15 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
}
Out << ")";
}
- if (!Proto.empty())
- Out << Proto;
- } else {
+ } else if (!ConversionDecl) {
if (FT && FT->hasTrailingReturn()) {
Out << "auto " << Proto << " -> ";
Proto.clear();
}
AFT->getReturnType().print(Out, Policy, Proto);
+ Proto.clear();
}
+ Out << Proto;
} else {
Ty.print(Out, Policy, Proto);
}
diff --git a/clang/lib/AST/DeclarationName.cpp b/clang/lib/AST/DeclarationName.cpp
index e5019ab8d9f..f9041c043c9 100644
--- a/clang/lib/AST/DeclarationName.cpp
+++ b/clang/lib/AST/DeclarationName.cpp
@@ -191,6 +191,7 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
return OS << *Rec->getDecl();
LangOptions LO;
LO.CPlusPlus = true;
+ LO.Bool = true;
return OS << Type.getAsString(PrintingPolicy(LO));
}
case DeclarationName::CXXUsingDirective:
@@ -546,6 +547,7 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const {
OS << "operator ";
LangOptions LO;
LO.CPlusPlus = true;
+ LO.Bool = true;
OS << TInfo->getType().getAsString(PrintingPolicy(LO));
} else
OS << Name;
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 8ed2987e6dd..a9f49990ee5 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -1296,6 +1296,12 @@ void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) {
}
void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
+ // If we have a conversion operator call only print the argument.
+ CXXMethodDecl *MD = Node->getMethodDecl();
+ if (MD && isa<CXXConversionDecl>(MD)) {
+ PrintExpr(Node->getImplicitObjectArgument());
+ return;
+ }
VisitCallExpr(cast<CallExpr>(Node));
}
diff --git a/clang/test/SemaCXX/ast-print.cpp b/clang/test/SemaCXX/ast-print.cpp
index 977ba7afa4d..3d98fd8ef3a 100644
--- a/clang/test/SemaCXX/ast-print.cpp
+++ b/clang/test/SemaCXX/ast-print.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -ast-print %s -std=gnu++11 | FileCheck %s
// CHECK: r;
// CHECK-NEXT: (r->method());
@@ -173,3 +173,26 @@ void test14() {
float test15() {
return __builtin_asinf(1.0F);
}
+
+namespace PR18776 {
+struct A {
+ operator void *();
+ explicit operator bool();
+ A operator&(A);
+};
+
+// CHECK: struct A
+// CHECK-NEXT: {{^[ ]*operator}} void *();
+// CHECK-NEXT: {{^[ ]*explicit}} operator bool();
+
+void bar(void *);
+
+void foo() {
+ A a, b;
+ bar(a & b);
+// CHECK: bar(a & b);
+ if (a & b)
+// CHECK: if (a & b)
+ return;
+}
+};
OpenPOWER on IntegriCloud