[PATCH] Fix PR19169:Crash on invalid attempting to specialize a template method as a template variable
Karthik Bhat
kv.bhat at samsung.com
Mon Apr 21 06:42:05 PDT 2014
Hi Richard,
Thanks a lot for your valuable inputs. Modified the diagnostic as per comments. I will try to address adding fixit for these cases in later revisions.
For now does this look good to commit?
Thanks again for spending your time on this i really appreciate your help.
Regards
Karthik Bhat
Hi rsmith, nicholas, aaron.ballman,
http://reviews.llvm.org/D3198
CHANGE SINCE LAST DIFF
http://reviews.llvm.org/D3198?vs=8156&id=8697#toc
Files:
lib/Sema/SemaTemplate.cpp
test/SemaCXX/cxx1y-variable-templates_top_level.cpp
include/clang/Basic/DiagnosticSemaKinds.td
Index: lib/Sema/SemaTemplate.cpp
===================================================================
--- lib/Sema/SemaTemplate.cpp
+++ lib/Sema/SemaTemplate.cpp
@@ -2419,10 +2419,27 @@
// The template-id must name a variable template.
VarTemplateDecl *VarTemplate =
- dyn_cast<VarTemplateDecl>(Name.getAsTemplateDecl());
- if (!VarTemplate)
+ dyn_cast_or_null<VarTemplateDecl>(Name.getAsTemplateDecl());
+ if (!VarTemplate) {
+ FunctionTemplateDecl *FnTemplate =
+ dyn_cast_or_null<FunctionTemplateDecl>(Name.getAsTemplateDecl());
+ if (FnTemplate) {
+ return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
+ << FnTemplate->getDeclName();
+ }
+ else {
+ if (OverloadedTemplateStorage *OST = Name.getAsOverloadedTemplate()) {
+ OverloadedTemplateStorage::iterator I = OST->begin();
+ OverloadedTemplateStorage::iterator IEnd = OST->end();
+ if (I != IEnd) {
+ return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template_but_method)
+ << (*I)->getDeclName();
+ }
+ }
+ }
return Diag(D.getIdentifierLoc(), diag::err_var_spec_no_template)
<< IsPartialSpecialization;
+ }
// Check for unexpanded parameter packs in any of the template arguments.
for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
Index: test/SemaCXX/cxx1y-variable-templates_top_level.cpp
===================================================================
--- test/SemaCXX/cxx1y-variable-templates_top_level.cpp
+++ test/SemaCXX/cxx1y-variable-templates_top_level.cpp
@@ -448,3 +448,12 @@
static_assert(x<int> == 1, "");
#endif
}
+
+namespace PR19169 {
+ template <typename T> int* f();
+ template <typename T> void f();
+ template<> int f<double>; // expected-error {{no variable template matches specialization; did you mean to use 'f' as function template instead?}}
+
+ template <typename T> void g();
+ template<> int g<double>; // expected-error {{no variable template matches specialization; did you mean to use 'g' as function template instead?}}
+}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3308,6 +3308,9 @@
"previous declaration of variable template partial specialization is here">;
def err_var_spec_no_template : Error<
"no variable template matches%select{| partial}0 specialization">;
+def err_var_spec_no_template_but_method : Error<
+ "no variable template matches specialization; "
+ "did you mean to use %0 as function template instead?">;
// C++ Function template specializations
def err_function_template_spec_no_match : Error<
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3198.3.patch
Type: text/x-patch
Size: 2803 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140421/ec7b50cb/attachment.bin>
More information about the cfe-commits
mailing list