[clang] [clang] Reject enum element types in ext_vector_type (PR #228863)

Shengxin Pei via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 4 05:20:12 PDT 2026


================
@@ -336,6 +336,34 @@ const int &reference_to_vec_element = vi4(1).x;
 // PR12649
 typedef bool bad __attribute__((__vector_size__(16)));  // expected-error {{invalid vector element type 'bool'}}
 
+namespace GH225037 {
+enum E { A };
+typedef E EnumVector __attribute__((ext_vector_type(4))); // expected-error {{invalid vector element type 'E'}}
+
+#if __cplusplus >= 201103L
+enum class ScopedE { A };
+typedef ScopedE ScopedEnumVector __attribute__((ext_vector_type(4))); // expected-error {{invalid vector element type 'ScopedE'}}
+#endif
+
+template <typename T> struct Vector {
+  // Rebuilding a fixed-size extended vector currently loses the attribute location.
+  typedef T type __attribute__((ext_vector_type(4))); // expected-error@*:* {{invalid vector element type 'GH225037::E'}}
+};
+Vector<E> enum_vector; // expected-note {{in instantiation of template class 'GH225037::Vector<GH225037::E>' requested here}}
+Vector<int> int_vector;
+Vector<bool> bool_vector;
+
+template <typename T, int N> struct DependentSizeVector {
+  typedef T type __attribute__((ext_vector_type(N))); // expected-error {{invalid vector element type 'GH225037::E'}}
+};
+DependentSizeVector<E, 4> dependent_enum_vector; // expected-note {{in instantiation of template class 'GH225037::DependentSizeVector<GH225037::E, 4>' requested here}}
+DependentSizeVector<float, 4> float_vector;
+
+template <int N> struct EnumVectorWithDependentSize {
+  typedef E type __attribute__((ext_vector_type(N))); // expected-error {{invalid vector element type 'E'}}
+};
+} // namespace GH225037
+
----------------
TPPPP72 wrote:

Looks pretty good.

https://github.com/llvm/llvm-project/pull/228863


More information about the cfe-commits mailing list