[clang] [Clang][Sema] Reject template arguments not equivalent to their copies (part of P2308R1) (PR #193754)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 07:09:53 PDT 2026


================
@@ -7130,6 +7130,71 @@ static bool CheckTemplateArgumentPointerToMember(
   return true;
 }
 
+// P2308R1  C++26 [temp.arg.nontype]p4:
+//   ... If, for the initialization from any candidate initializer,
+//     - ...
+//     - the initialization would cause P to not be
+//       template-argument-equivalent ([temp.type]) to v,
+//   the program is ill-formed.
+static bool CheckTemplateArgumentCopyEquivalence(Sema &S, NamedDecl *Param,
+                                                 QualType ParamType,
+                                                 const APValue &Value,
+                                                 SourceLocation ArgLoc) {
+  assert(ParamType->isRecordType() && "no need to check copy equivalence");
+
+  if (ParamType->castAsCXXRecordDecl()->isTriviallyCopyTemplateParam())
+    return false;
+
+  SourceLocation ParamLoc = Param->getLocation();
+
+  // Instead of creating a variable (C++26 [temp.arg.nontype]p3),
+  // create a template parameter object to represent the candidate initializer.
+  // They are equivalent during creating a copy.
----------------
cor3ntin wrote:

```suggestion
  // They are equivalent when creating a copy.
```

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


More information about the cfe-commits mailing list