[PATCH] D15509: Suggest missing 'template' for dependent member templates

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 15 15:04:14 PDT 2016


rsmith requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: lib/Parse/ParseTemplate.cpp:1233-1240
@@ -1240,1 +1232,10 @@
+
+  SuppressAllDiagnostics S(Diags);
+  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
+  TemplateArgList TemplateArgs;
+  if (ParseTemplateArgumentList(TemplateArgs))
+    return false;
+
+  // Closing '>'
+  return Tok.is(tok::greater);
 }
----------------
This looks wrong: it will parse anything that could be a template argument list as a template argument list. In ambiguous cases, we must parse as a `<` operator.

================
Comment at: test/SemaTemplate/dependent-template-recover.cpp:14-15
@@ -13,5 +13,4 @@
 
-    // FIXME: We can't recover from these yet
-    (*t).f2<N>(); // expected-error{{expected expression}}
-    (*t).f2<0>(); // expected-error{{expected expression}}
+    (*t).f2<N>(); // expected-error{{use 'template' keyword to treat 'f2' as a dependent template name}}
+    (*t).f2<0>(); // expected-error{{use 'template' keyword to treat 'f2' as a dependent template name}}
   }
----------------
I think you will incorrectly treat

    (*t).f2<0>(0);

... as a dependent template name. Instead, it's required to be parsed as

  ((*t.f2) < 0) > 0;

================
Comment at: test/SemaTemplate/dependent-template-recover.cpp:35
@@ +34,3 @@
+  s.foo<1>(); // expected-error{{use 'template' keyword to treat 'foo' as a dependent template name}}
+  s.foo<1>(0); // expected-error{{use 'template' keyword to treat 'foo' as a dependent template name}}
+}
----------------
This diagnostic is incorrect.


http://reviews.llvm.org/D15509





More information about the cfe-commits mailing list