[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

Robert Esclapez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 23 06:58:24 PDT 2022


roberteg16 updated this revision to Diff 431356.
roberteg16 added a comment.

Stricten comparison


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126172/new/

https://reviews.llvm.org/D126172

Files:
  clang/lib/AST/TemplateBase.cpp
  clang/test/CXX/dcl/dcl.fct/p17.cpp


Index: clang/test/CXX/dcl/dcl.fct/p17.cpp
===================================================================
--- clang/test/CXX/dcl/dcl.fct/p17.cpp
+++ clang/test/CXX/dcl/dcl.fct/p17.cpp
@@ -257,4 +257,23 @@
   static_assert(is_same_v<decltype(S2(1)), S2>);
   // expected-error at -1{{no matching}}
   static_assert(is_same_v<decltype(S2('a')), S2>);
-}
+
+  // clang-format off
+  template <typename T> struct S3 {};
+  // expected-note at -1 {{'S3' declared here}}
+  // expected-note at -2 {{template is declared here}}
+  void f23(C2<::S3> auto);
+  // expected-error at -1 {{no template named 'S3' in the global namespace; did you mean simply 'S3'?}}
+  // expected-error at -2 {{use of class template '::S3' requires template arguments}}
+  // clang-format on
+} // namespace constrained
+
+template <typename T> struct S4 {};
+// expected-note at -1 {{template is declared here}}
+
+namespace constrained {
+// clang-format off
+void f24(C2<::S4> auto);
+// expected-error at -1 {{use of class template '::S4' requires template arguments}}
+// clang-format on
+} // namespace constrained
Index: clang/lib/AST/TemplateBase.cpp
===================================================================
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -370,7 +370,8 @@
 
   case Template:
   case TemplateExpansion:
-    return TemplateArg.Name == Other.TemplateArg.Name &&
+    return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+               Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl() &&
            TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;
 
   case Declaration:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126172.431356.patch
Type: text/x-patch
Size: 1620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220523/2060f82f/attachment.bin>


More information about the cfe-commits mailing list