forked from OSchip/llvm-project
Sema: Allow 'constexpr' variables in range loops
This fixes PR22492, which is in response to CWG issue #1204. Per the CWG issue 'contexpr' variables are now allowed in for range loops. llvm-svn: 229716
This commit is contained in:
parent
527c5dc68d
commit
34e79ed319
|
@ -9371,8 +9371,6 @@ void Sema::ActOnCXXForRangeDecl(Decl *D) {
|
|||
case SC_OpenCLWorkGroupLocal:
|
||||
llvm_unreachable("Unexpected storage class");
|
||||
}
|
||||
if (VD->isConstexpr())
|
||||
Error = 5;
|
||||
if (Error != -1) {
|
||||
Diag(VD->getOuterLocStart(), diag::err_for_range_storage_class)
|
||||
<< VD->getDeclName() << Error;
|
||||
|
|
|
@ -50,6 +50,18 @@ namespace X {
|
|||
struct NoEndADL {
|
||||
null_t alt_begin();
|
||||
};
|
||||
|
||||
struct C {
|
||||
C();
|
||||
struct It {
|
||||
int val;
|
||||
operator int &() { return val; }
|
||||
};
|
||||
It begin();
|
||||
It end();
|
||||
};
|
||||
|
||||
constexpr int operator*(const C::It &) { return 0; }
|
||||
}
|
||||
|
||||
using X::A;
|
||||
|
@ -118,7 +130,7 @@ void g() {
|
|||
for (extern int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'extern'}}
|
||||
for (static int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'static'}}
|
||||
for (register int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'register'}} expected-warning {{deprecated}}
|
||||
for (constexpr int a : A()) {} // expected-error {{loop variable 'a' may not be declared 'constexpr'}}
|
||||
for (constexpr int a : X::C()) {} // OK per CWG issue #1204.
|
||||
|
||||
for (auto u : X::NoBeginADL()) { // expected-error {{invalid range expression of type 'X::NoBeginADL'; no viable 'begin' function available}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue