[PATCH] D16396: Warn if variable cannot be implicitly instantiated

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 18 10:58:58 PDT 2016


rsmith added a comment.

Are you planning on extending this to also cover templated functions?


================
Comment at: include/clang/Basic/DiagnosticGroups.td:78
@@ -77,2 +77,3 @@
   DiagGroup<"gnu-string-literal-operator-template">;
+def UnavailableTemplate : DiagGroup<"unavailable-template">;
 
----------------
undefined rather than unavailable? "unavailable" means something different in Clang.

================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:3826
@@ +3825,3 @@
+def warn_var_template_missing : Warning<"instantiation of %q0 required here, "
+  "but corresponding template is not found">, InGroup<UnavailableTemplate>;
+def note_inst_declaration_hint : Note<"add an explicit instantiation declaration "
----------------
not found -> not defined? The template is found, or the code would be ill-formed.

Also, 'corresponding template' isn't quite right; in `S<int>::m`, the template is `S`, which must be defined. Maybe you could map to the pattern declaration for the instantiation, and warn that it isn't defined, so we'd say something like

 "instantiation of 'S<int>::m' required here, but 'S<T>::m' is not defined"

================
Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3909
@@ +3908,3 @@
+          << Var;
+        Diag(PointOfInstantiation, diag::note_inst_declaration_hint) << Var;
+      }
----------------
Explicit instantiation declarations are a C++11 feature. Should we suppress this warning, or at least the note, in C++98?


http://reviews.llvm.org/D16396





More information about the cfe-commits mailing list