This is an archive of the discontinued LLVM Phabricator instance.

Add diagnostic for for-range-declaration being specificed with thread_local
ClosedPublic

Authored by shafik on Dec 4 2020, 10:23 AM.

Details

Summary

Currently we have a diagnostic that catches the other storage class specifies for the range based for loop declaration but we miss the thread_local case. This changes adds a diagnostic for that case as well.

Diff Detail

Event Timeline

shafik requested review of this revision.Dec 4 2020, 10:23 AM
shafik created this revision.

The problem with this approach is given:

for (static thread_local int a : A()) {}

it just issues one diagnostic and it points to static but I am not sure what the right approach to handling this case is.

Spoilsport. ;)
LGTM, fwiw.

clang/lib/Sema/SemaDecl.cpp
12783

Incidentally, why is this case here to begin with? Loop variables can totally be register. (But I guess it's moot at this point; clearly no Clang user is depending on this to work, and register is gone from C++20.)

aaron.ballman accepted this revision.Dec 4 2020, 1:14 PM

LGTM!

The problem with this approach is given:

for (static thread_local int a : A()) {}

it just issues one diagnostic and it points to static but I am not sure what the right approach to handling this case is.

I think that's reasonable behavior for this corner case.

clang/lib/Sema/SemaDecl.cpp
12783

See [stmt.ranged]p2 -- it's explicitly disallowed. FWIW, loop variables in C++ can also be static (https://godbolt.org/z/rM15Yz). ;-)

This revision is now accepted and ready to land.Dec 4 2020, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 3:06 PM