[clang] [Clang][Sema] Error message refers to `__begin1` with `constexpr` variable in range-based for loop (PR #218145)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 26 03:13:45 PDT 2026
tbaederr wrote:
I don't quite get the new diagnostic; sure the variable is initialized no each iteration, but the problem at hand is that the initialization itself fails, i.e. even if the initializer _is_ constexpr, the implicit variable isn't and the initializer fails as well: https://godbolt.org/z/jMMYjEjhz
In fact, the only test we seem to have with for-range loops and a constexpr iterator variable is in `test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp`:
```c++
namespace X {
struct C {
struct It {
int val;
operator int &() { return val; }
};
It begin();
It end();
};
constexpr int operator*(const C::It &) { return 0; }
};
void f2() {
for (constexpr int a : X::C()) {}
}
```
This _does_ work but it seems to be the only construct?
Anyway, this probably goes beyond the scope of the PR and requires someone with more knowledge of the spec (shouldn't we make `__begin1` constexpr if `a` is?).
https://github.com/llvm/llvm-project/pull/218145
More information about the cfe-commits
mailing list