[clang] 7602ef7 - Suppress trailing template arguments equivalent to default arguments

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 12 21:10:45 PST 2020


Author: Richard Smith
Date: 2020-11-12T21:10:34-08:00
New Revision: 7602ef768b1af99b6184faf6edfc4e06b718c7c5

URL: https://github.com/llvm/llvm-project/commit/7602ef768b1af99b6184faf6edfc4e06b718c7c5
DIFF: https://github.com/llvm/llvm-project/commit/7602ef768b1af99b6184faf6edfc4e06b718c7c5.diff

LOG: Suppress trailing template arguments equivalent to default arguments
when printing the name of a member of a class template specialization.

Added: 
    

Modified: 
    clang/lib/AST/Decl.cpp
    clang/test/CodeGenCXX/predefined-expr.cpp
    clang/test/Misc/diag-template.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 888999978466..8960d924d3fa 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1627,7 +1627,9 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
     if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
       OS << Spec->getName();
       const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
-      printTemplateArgumentList(OS, TemplateArgs.asArray(), P);
+      printTemplateArgumentList(
+          OS, TemplateArgs.asArray(), P,
+          Spec->getSpecializedTemplate()->getTemplateParameters());
     } else if (const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
       if (ND->isAnonymousNamespace()) {
         OS << (P.MSVCFormatting ? "`anonymous namespace\'"

diff  --git a/clang/test/CodeGenCXX/predefined-expr.cpp b/clang/test/CodeGenCXX/predefined-expr.cpp
index 21cceddf19e6..b8516691e0b1 100644
--- a/clang/test/CodeGenCXX/predefined-expr.cpp
+++ b/clang/test/CodeGenCXX/predefined-expr.cpp
@@ -7,7 +7,7 @@
 // CHECK-DAG: private unnamed_addr constant [95 x i8] c"void SpecializedClassTemplate<char>::memberFunctionTemplate(T, U) const [T = char, U = double]\00"
 // CHECK-DAG: private unnamed_addr constant [85 x i8] c"void SpecializedClassTemplate<int>::memberFunctionTemplate(int, U) const [U = float]\00"
 // CHECK-DAG: private unnamed_addr constant [57 x i8] c"void NonTypeTemplateParam<42>::size() const [Count = 42]\00"
-// CHECK-DAG: private unnamed_addr constant [122 x i8] c"static void ClassWithTemplateTemplateParam<char, NS::ClassTemplate>::staticMember() [T = char, Param = NS::ClassTemplate]\00"
+// CHECK-DAG: private unnamed_addr constant [103 x i8] c"static void ClassWithTemplateTemplateParam<char>::staticMember() [T = char, Param = NS::ClassTemplate]\00"
 // CHECK-DAG: private unnamed_addr constant [106 x i8] c"void OuterClass<int *>::MiddleClass::InnerClass<float>::memberFunction(T, U) const [T = int *, U = float]\00"
 // CHECK-DAG: private unnamed_addr constant [51 x i8] c"void functionTemplateWithCapturedStmt(T) [T = int]\00"
 // CHECK-DAG: private unnamed_addr constant [76 x i8] c"auto functionTemplateWithLambda(int)::(anonymous class)::operator()() const\00"

diff  --git a/clang/test/Misc/diag-template.cpp b/clang/test/Misc/diag-template.cpp
index 30d4829409bb..e207344c2e9f 100644
--- a/clang/test/Misc/diag-template.cpp
+++ b/clang/test/Misc/diag-template.cpp
@@ -15,11 +15,15 @@ namespace default_args {
   }
 
   template<typename T> struct default_delete {};
-  template<class T, class Deleter = default_delete<T>> class unique_ptr {};
+  template<class T, class Deleter = default_delete<T>> class unique_ptr {
+  public:
+    void f() { T::error(); } // expected-error {{no member named 'error' in 'default_args::basic_string<char>'}}
+  };
   template<class T, class Deleter> class unique_ptr<T[], Deleter> {};
   void test2() {
     unique_ptr<string> ups;
     f(ups).reset(); // expected-error {{no member named 'reset' in 'default_args::unique_ptr<default_args::basic_string<char>>'}}
+    f(ups).f(); // expected-note {{in instantiation of member function 'default_args::unique_ptr<default_args::basic_string<char>>::f' requested here}}
   }
 
   template<int A, int B = A> struct Z { int error[B]; }; // expected-error {{negative size}}


        


More information about the cfe-commits mailing list