[PATCH] D42170: Fixit for 'typedef' instead of 'typename' typo

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 22 19:23:54 PST 2018


vsapsai added inline comments.


================
Comment at: Parse/ParseTemplate.cpp:492
+  // Is there just a typo in the input code? ('typedef' instead of 'typename')
+  if (Tok.is(tok::kw_typedef)) {
+    Diag(Tok.getLocation(), diag::err_expected_template_parameter);
----------------
How does it work when you have `typedef` for the first template parameter?


================
Comment at: Parser/typedef-instead-of-typename-typo.hpp:3
+
+template <typename A, typedef B> struct Foo {
+  a
----------------
Maybe put this test in clang/test/FixIt ?

Also please check what file extensions are used for testing templates. .hpp reflects real-life usage but  most tests are .cpp. Or maybe I wasn't paying attention.


================
Comment at: Parser/typedef-instead-of-typename-typo.hpp:5
+  a
+}; // CHECK: expected-error{{expected template parameter}} \
+// CHECK: expected-note{{Did you mean to use 'typename'?}} \
----------------
It is a little bit confusing to what lines the messages would be attributed to. Need to check locally because not sure I interpret all those backslashes the same way lit does.

Also idea for the test. To check that the fix-it was applied properly you can add a member like `B b;` and it shouldn't trigger any errors.


================
Comment at: clang/Basic/DiagnosticParseKinds.td:1167
+def note_meant_to_use_typename : Note<
+  "Did you mean to use 'typename'?">;
 }
----------------
Looks like other diagnostic messages "did you mean to use …" have lowercase "d" in "did". Though I haven't checked how it looks in various situations.


https://reviews.llvm.org/D42170





More information about the cfe-commits mailing list