================
@@ -534,16 +557,43 @@ class TemplateArgumentLoc {
 
   TemplateArgumentLoc(const TemplateArgument &Argument,
                       TemplateArgumentLocInfo Opaque)
-      : Argument(Argument), LocInfo(Opaque) {}
+      : Argument(Argument), LocInfo(Opaque) {
+    switch (Argument.getKind()) {
+    case TemplateArgument::Null:
+      assert(Opaque.isNull());
+      return;
+    case TemplateArgument::Pack:
+      assert(Opaque.isTrivial());
+      return;
+    case TemplateArgument::NullPtr:
+    case TemplateArgument::Integral:
+    case TemplateArgument::Declaration:
+    case TemplateArgument::StructuralValue:
+      assert(Opaque.isTrivial() || Opaque.getAsExpr() != nullptr);
+      return;
+    case TemplateArgument::Expression:
+      assert(Opaque.getAsExpr() != nullptr);
+      return;
+    case TemplateArgument::Type:
+      assert(Opaque.getAsTypeSourceInfo() != nullptr);
+      return;
+    case TemplateArgument::Template:
+    case TemplateArgument::TemplateExpansion:
+      assert(Opaque.getTemplate() != nullptr);
----------------
chandlerc wrote:

All of these assertions seem to make it especially difficult to construct 
template arguments dynamically using the AST APIs, for example in a client like 
LLDB or in a frontend synthesizing interop with templates such as Swift, 
Crubit, or Carbon.

Would it be reasonable to accept null `LocInfo` in all of these cases rather 
than just when the argument kind itself is null? My understanding is that would 
allow everything downstream to continue working.

@zygoloid for visibility.

https://github.com/llvm/llvm-project/pull/187352
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to