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

Richard Smith richard-llvm at metafoo.co.uk
Tue Jan 21 16:27:42 PST 2014


Author: rsmith
Date: Tue Jan 21 18:27:42 2014
New Revision: 199778

URL: http://llvm.org/viewvc/llvm-project?rev=199778&view=rev
Log:
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!

Modified:
    cfe/trunk/lib/AST/DeclarationName.cpp
    cfe/trunk/test/CXX/class.access/p4.cpp
    cfe/trunk/test/CXX/class.access/p6.cpp
    cfe/trunk/test/CXX/special/class.dtor/p10-0x.cpp
    cfe/trunk/test/Index/load-classes.cpp
    cfe/trunk/test/SemaCXX/undefined-internal.cpp
    cfe/trunk/unittests/AST/DeclPrinterTest.cpp

Modified: cfe/trunk/lib/AST/DeclarationName.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclarationName.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclarationName.cpp (original)
+++ cfe/trunk/lib/AST/DeclarationName.cpp Tue Jan 21 18:27:42 2014
@@ -150,7 +150,9 @@ raw_ostream &operator<<(raw_ostream &OS,
     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,
     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,
     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_
         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;

Modified: cfe/trunk/test/CXX/class.access/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p4.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/p4.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p4.cpp Tue Jan 21 18:27:42 2014
@@ -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}}
   }
 }
 

Modified: cfe/trunk/test/CXX/class.access/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p6.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/p6.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p6.cpp Tue Jan 21 18:27:42 2014
@@ -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'}}
   }
 }
 

Modified: cfe/trunk/test/CXX/special/class.dtor/p10-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/special/class.dtor/p10-0x.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/test/CXX/special/class.dtor/p10-0x.cpp (original)
+++ cfe/trunk/test/CXX/special/class.dtor/p10-0x.cpp Tue Jan 21 18:27:42 2014
@@ -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}}

Modified: cfe/trunk/test/Index/load-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-classes.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/test/Index/load-classes.cpp (original)
+++ cfe/trunk/test/Index/load-classes.cpp Tue Jan 21 18:27:42 2014
@@ -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]

Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Tue Jan 21 18:27:42 2014
@@ -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 {

Modified: cfe/trunk/unittests/AST/DeclPrinterTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/DeclPrinterTest.cpp?rev=199778&r1=199777&r2=199778&view=diff
==============================================================================
--- cfe/trunk/unittests/AST/DeclPrinterTest.cpp (original)
+++ cfe/trunk/unittests/AST/DeclPrinterTest.cpp Tue Jan 21 18:27:42 2014
@@ -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();"
 }
 





More information about the cfe-commits mailing list