================
@@ -501,3 +501,11 @@ namespace SubPtr {
                                                      // both-note {{subtracted 
pointers are not elements of the same array}}
   constexpr auto diff8 = &a[1][2].n - (&a[1][2].n + 1);
 }
+
+namespace ConstexprForRangeVar {
+  void f() {
+    int arr[] = {1, 2, 3};
+    for (constexpr int a : arr) {} // both-error {{constexpr variable 'a' must 
be initialized by a constant expression}} \
+                                   // both-note {{range-based for loop 
variable is initialized on each iteration from the loop's iterator, whose value 
is not known at compile time}}
----------------
zyn0217 wrote:

I think a better diagnostic would be like
```
error: constexpr variable 'a' must be initialized by a constant expression
note: because `arr` is not a constant expression / known at compile time
```

https://github.com/llvm/llvm-project/pull/218145
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to