r189716 - The diagnostic err_init_conversion_failed uses the enum

Richard Trieu rtrieu at google.com
Fri Aug 30 20:50:47 PDT 2013


Author: rtrieu
Date: Fri Aug 30 22:50:47 2013
New Revision: 189716

URL: http://llvm.org/viewvc/llvm-project?rev=189716&view=rev
Log:
The diagnostic err_init_conversion_failed uses the enum
InitializedEntity::EntityKind as an index for one of its %select.  Over time,
EntityKind has been expanded, but the diagnostic text has not been updated.
This adds additional text to the %select to cover the new enum values.  A
comment has been added to the end of the enum regarding this situation.  This
fixes the crasher in PR17043.

Added:
    cfe/trunk/test/SemaCXX/err_init_conversion_failed.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/include/clang/Sema/Initialization.h

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=189716&r1=189715&r2=189716&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Aug 30 22:50:47 2013
@@ -1297,7 +1297,9 @@ def err_destructor_template : Error<
 def err_init_conversion_failed : Error<
   "cannot initialize %select{a variable|a parameter|return object|an "
   "exception object|a member subobject|an array element|a new value|a value|a "
-  "base class|a constructor delegation|a vector element}0 "
+  "base class|a constructor delegation|a vector element|a block element|a "
+  "complex element|a lambda capture|a compound literal initializer|a "
+  "related result|a parameter of CF audited function}0 "
   "%diff{of type $ with an %select{rvalue|lvalue}2 of type $|"
   "with an %select{rvalue|lvalue}2 of incompatible type}1,3"
   "%select{|: different classes%diff{ ($ vs $)|}5,6"

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=189716&r1=189715&r2=189716&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Fri Aug 30 22:50:47 2013
@@ -86,6 +86,10 @@ public:
     /// \brief The entity being initialized is a function parameter; function
     /// is member of group of audited CF APIs.
     EK_Parameter_CF_Audited
+
+    // Note: err_init_conversion_failed in DiagnosticSemaKinds.td uses this
+    // enum as an index for its first %select.  When modifying this list,
+    // that diagnostic text needs to be updated as well.
   };
   
 private:

Added: cfe/trunk/test/SemaCXX/err_init_conversion_failed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/err_init_conversion_failed.cpp?rev=189716&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/err_init_conversion_failed.cpp (added)
+++ cfe/trunk/test/SemaCXX/err_init_conversion_failed.cpp Fri Aug 30 22:50:47 2013
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void test0() {
+  char variable = (void)0;
+  // expected-error at -1{{cannot initialize a variable}}
+}
+
+void test1(int x = (void)0) {}
+  // expected-error at -1{{cannot initialize a parameter}}
+  // expected-note at -2{{here}}
+
+int test2() {
+  return (void)0;
+  // expected-error at -1{{cannot initialize return object}}
+}
+
+struct S4 {
+  S4() : x((void)0) {};
+  // expected-error at -1{{cannot initialize a member subobject}}
+  int x;
+};
+
+void test5() {
+  int foo[2] = {1, (void)0};
+  // expected-error at -1{{cannot initialize an array element}}
+}
+
+void test6() {
+  new int((void)0);
+  // expected-error at -1{{cannot initialize a new value}}
+}
+
+typedef short short2 __attribute__ ((__vector_size__ (2)));
+void test10() {
+  short2 V = { (void)0 };
+  // expected-error at -1{{cannot initialize a vector element}}
+}
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+typedef float float4 __attribute__((ext_vector_type(4)));
+
+void test14(const float2 in, const float2 out) {
+  const float4 V = (float4){ in, out };
+  // expected-error at -1{{cannot initialize a compound literal initializer}}
+}





More information about the cfe-commits mailing list