[clang] [Clang] Do not allowed narrowing in pack indexing expression. (PR #206040)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 08:19:18 PDT 2026


================
@@ -46,20 +46,22 @@ void test() {
     params<1>(0);  // expected-note{{here}} \
                    // expected-error@#error-param-size {{invalid index 1 for pack 'p' of size 1}}
     params<-1>(0); // expected-note{{here}} \
-                   // expected-error@#error-param-size {{invalid index -1 for pack 'p' of size 1}}
+                   // expected-error@#error-param-size {{evaluates to -1, which cannot be narrowed to type '__size_t' (aka 'unsigned long')}}
 
     test_types<-1>(); //expected-note {{in instantiation}} \
-                      // expected-error@#error-type-size {{invalid index -1 for pack 'T' of size 0}}
-    test_types<-1, int>(); //expected-note {{in instantiation}} \
-                      // expected-error@#error-type-size {{invalid index -1 for pack 'T' of size 1}}
+                      // expected-error@#error-type-size {{evaluates to -1, which cannot be narrowed to type '__size_t' (aka 'unsigned long')}}
+
+    test_types<-1, int>(); // expected-note {{in instantiation}} \
+                           // expected-error@#error-type-size {{evaluates to -1, which cannot be narrowed to type '__size_t' (aka 'unsigned long')}}
+
     test_types<0>(); //expected-note {{in instantiation}} \
                     // expected-error@#error-type-size {{invalid index 0 for pack 'T' of size 0}}
     test_types<1, int>(); //expected-note {{in instantiation}}  \
                          // expected-error@#error-type-size {{invalid index 1 for pack 'T' of size 1}}
 }
 
 void invalid_indexes(auto... p) {
-    p...[non_constant_index()]; // expected-error {{array size is not a constant expression}}\
+    p...[non_constant_index()]; // expected-error {{pack index is not a constant expression}}\
----------------
shafik wrote:

Is it really the pack index that is a not a constant expression? I feel like array size still make sense. I guess maybe it is but it feels confusing. I feel like we should be saying something about the array size or `non_constant_index`.

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


More information about the cfe-commits mailing list