[PATCH] Bug fix: note diagnosis on expression narrowing...

Larisse Voufo lvoufo at google.com
Tue Aug 13 15:08:44 PDT 2013


Hi rsmith,

... should say "variable template" instead of "static data member" when appropriate.
(See test case update in patch.)

http://llvm-reviews.chandlerc.com/D1391

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaTemplateInstantiate.cpp
  test/SemaCXX/cxx1y-variable-templates_top_level.cpp

Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3169,6 +3169,8 @@
   "in instantiation of function template specialization %q0 requested here">;
 def note_template_static_data_member_def_here : Note<
   "in instantiation of static data member %q0 requested here">;
+def note_template_variable_def_here : Note<
+  "in instantiation of variable template specialization %q0 requested here">;
 def note_template_enum_def_here : Note<
   "in instantiation of enumeration %q0 requested here">;
 def note_template_type_alias_instantiation_here : Note<
Index: lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiate.cpp
+++ lib/Sema/SemaTemplateInstantiate.cpp
@@ -524,7 +524,9 @@
           << Active->InstantiationRange;
       } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
         Diags.Report(Active->PointOfInstantiation,
-                     diag::note_template_static_data_member_def_here)
+                     VD->isStaticDataMember()?
+                       diag::note_template_static_data_member_def_here
+                     : diag::note_template_variable_def_here)
           << VD
           << Active->InstantiationRange;
       } else if (EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
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
@@ -123,7 +123,7 @@
   }
 #endif
   
-}  
+}
 
 namespace explicit_instantiation {
   template<typename T> 
@@ -318,6 +318,15 @@
   }
 }
 
+namespace narrowing {
+  template<typename T> T v = {1234};  // expected-warning {{implicit conversion from 'int' to 'char' changes value from 1234 to}}
+#ifdef CXX11
+  // expected-error at -2 {{constant expression evaluates to 1234 which cannot be narrowed to type 'char'}}\
+  // expected-note at -2 {{override this message by inserting an explicit cast}}
+#endif
+  int k = v<char>;        // expected-note {{in instantiation of variable template specialization 'narrowing::v<char>' requested here}}
+}
+
 namespace use_in_structs {
   // TODO:
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1391.1.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130813/476f87ef/attachment.bin>


More information about the cfe-commits mailing list