When formatting a C++-only declaration name, enable C++ mode in the formatter's

language options. This is not really ideal -- we should require the right
language options to be passed in, or not require language options to format a
name -- but it fixes a number of *obviously* wrong formattings. Patch by
Olivier Goffart!

llvm-svn: 199778
This commit is contained in:
Richard Smith 2014-01-22 00:27:42 +00:00
parent 6ba68f10c4
commit e81daee21b
7 changed files with 19 additions and 11 deletions

View File

@ -150,7 +150,9 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
QualType ClassType = N.getCXXNameType();
if (const RecordType *ClassRec = ClassType->getAs<RecordType>())
return OS << *ClassRec->getDecl();
return OS << ClassType.getAsString();
LangOptions LO;
LO.CPlusPlus = true;
return OS << ClassType.getAsString(PrintingPolicy(LO));
}
case DeclarationName::CXXDestructorName: {
@ -158,7 +160,9 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
QualType Type = N.getCXXNameType();
if (const RecordType *Rec = Type->getAs<RecordType>())
return OS << *Rec->getDecl();
return OS << Type.getAsString();
LangOptions LO;
LO.CPlusPlus = true;
return OS << Type.getAsString(PrintingPolicy(LO));
}
case DeclarationName::CXXOperatorName: {
@ -185,7 +189,9 @@ raw_ostream &operator<<(raw_ostream &OS, DeclarationName N) {
QualType Type = N.getCXXNameType();
if (const RecordType *Rec = Type->getAs<RecordType>())
return OS << *Rec->getDecl();
return OS << Type.getAsString();
LangOptions LO;
LO.CPlusPlus = true;
return OS << Type.getAsString(PrintingPolicy(LO));
}
case DeclarationName::CXXUsingDirective:
return OS << "<using-directive>";
@ -538,7 +544,9 @@ void DeclarationNameInfo::printName(raw_ostream &OS) const {
OS << '~';
else if (Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
OS << "operator ";
OS << TInfo->getType().getAsString();
LangOptions LO;
LO.CPlusPlus = true;
OS << TInfo->getType().getAsString(PrintingPolicy(LO));
} else
OS << Name;
return;

View File

@ -79,8 +79,8 @@ namespace test1 {
-ca;
// These are all surrogate calls
ca(pub);
ca(prot); // expected-error {{'operator void (*)(class Protected &)' is a protected member}}
ca(priv); // expected-error {{'operator void (*)(class Private &)' is a private member}}
ca(prot); // expected-error {{'operator void (*)(Protected &)' is a protected member}}
ca(priv); // expected-error {{'operator void (*)(Private &)' is a private member}}
}
}

View File

@ -177,7 +177,7 @@ namespace test8 {
};
void test(A &a) {
if (a) return; // expected-error-re {{'operator void *(class test8::A::*)(void){{( __attribute__\(\(thiscall\)\))?}} const' is a private member of 'test8::A'}}
if (a) return; // expected-error-re {{'operator void *(test8::A::*)(){{( __attribute__\(\(thiscall\)\))?}} const' is a private member of 'test8::A'}}
}
}

View File

@ -7,7 +7,7 @@ template<typename T>
void b(const T *x, const A *y) {
x->~decltype(T())();
x->~decltype(*x)(); // expected-error{{the type of object expression ('const int') does not match the type being destroyed ('decltype(*x)' (aka 'const int &')) in pseudo-destructor expression}} \
expected-error{{no member named '~const struct A &' in 'A'}}
expected-error{{no member named '~const A &' in 'A'}}
x->~decltype(int())(); // expected-error{{no member named '~int' in 'A'}}
y->~decltype(*y)(); // expected-error{{destructor type 'decltype(*y)' (aka 'const A &') in object destruction expression does not match the type 'const A' of the object being destroyed}}

View File

@ -23,7 +23,7 @@ X::X(int value) {
// CHECK: load-classes.cpp:5:11: TypeRef=struct X:3:8 Extent=[5:11 - 5:12]
// CHECK: load-classes.cpp:7:3: CXXDestructor=~X:7:3 Extent=[7:3 - 7:7] [access=protected]
// FIXME: missing TypeRef in the destructor name
// CHECK: load-classes.cpp:9:3: CXXConversion=operator struct X *:9:3 Extent=[9:3 - 9:16] [access=private]
// CHECK: load-classes.cpp:9:3: CXXConversion=operator X *:9:3 Extent=[9:3 - 9:16] [access=private]
// CHECK: load-classes.cpp:9:12: TypeRef=struct X:3:8 Extent=[9:12 - 9:13]
// CHECK: load-classes.cpp:12:4: CXXConstructor=X:12:4 (Definition) Extent=[12:1 - 13:2] [access=public]
// CHECK: load-classes.cpp:12:1: TypeRef=struct X:3:8 Extent=[12:1 - 12:2]

View File

@ -288,7 +288,7 @@ namespace test12 {
virtual operator T3&() = 0;
operator T4(); // expected-warning {{function 'test12::<anonymous namespace>::Cls::operator T4' has internal linkage but is not defined}}
operator T5(); // expected-warning {{function 'test12::<anonymous namespace>::Cls::operator T5' has internal linkage but is not defined}}
operator T6&(); // expected-warning {{function 'test12::<anonymous namespace>::Cls::operator class test12::T6 &' has internal linkage but is not defined}}
operator T6&(); // expected-warning {{function 'test12::<anonymous namespace>::Cls::operator test12::T6 &' has internal linkage but is not defined}}
};
struct Cls2 {

View File

@ -558,7 +558,7 @@ TEST(DeclPrinter, TestCXXConversionDecl3) {
" operator Z();"
"};",
methodDecl(ofClass(hasName("A"))).bind("id"),
"Z operator struct Z()"));
"Z operator Z()"));
// WRONG; Should be: "operator Z();"
}