rsmith added a subscriber: rsmith.
rsmith added a comment.

It seems useful to warn on this, but I'm concerned that there are valid code 
patterns that this will warn about where there is no reasonable way to rewrite 
the code that would suppress the warning. For instance:

  template<typename T> class X {
    friend void process(X<T>);
    // ...
  };
  void process(X<int>) { /* ... */ }
  void process(X<char>) ( /* ... */ }

As an alternative, can we suppress the warning until we see an "almost 
matching" template declaration in the surrounding scope? For instance:

  template<typename T> void process(X<T>) { /* ... */ } // warning, not a 
friend of X<T>


================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1155-1157
@@ -1153,1 +1154,5 @@
+  "non-template function">, InGroup<NonTemplateFriend>;
+def note_non_template_friend : Note<"if this is not what you intended, make "
+  "sure the function template has already been declared and add <> after the "
+  "function name here">;
 
----------------
Maybe just: "to befriend a template specialization, use <>", along with a 
FixItHint showing where to add the <>.

It would also seem like a good idea to check if there is such a function 
template declared, and give different diagnostic if not.


http://reviews.llvm.org/D16579



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to