[clang] [clang][Sema] Fix a CTAD regression after 42239d2e9 (PR #86914)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 28 01:42:43 PDT 2024


================
@@ -1836,7 +1836,19 @@ static TemplateParameterList *GetTemplateParameterList(TemplateDecl *TD) {
   // Make sure we get the template parameter list from the most
   // recent declaration, since that is the only one that is guaranteed to
   // have all the default template argument information.
-  return cast<TemplateDecl>(TD->getMostRecentDecl())->getTemplateParameters();
+  Decl *ND = TD->getMostRecentDecl();
+  // Skip past friend Decls because they are not supposed to contain default
+  // template arguments. Moreover, these declarations may introduce template
+  // parameters living in different template depths than the corresponding
+  // template parameters in TD, causing unmatched constraint substitution.
+  //
+  // C++23 N4950 [temp.param]p12
----------------
hokein wrote:

nit: this is not a new thing in C++23, I also find it in the C++20 spec N4860. I'd remove the `C++23 N4950`.

And I think this is also a FIXME, clang should diagnose this error case, maybe add the `FIXME` in the comment.

I think this function is not only used for class templates, but also for function templates. For function templates, there is an exception per the standard (temp.param 12): `If a friend function template declaration specifies a default template-argument, that declaration shall be a definition and shall be the only declaration of the function template in the translation unit.`


https://github.com/llvm/llvm-project/pull/86914


More information about the cfe-commits mailing list