From 6e4c907c67457f6779b721d67697260f7901f03a Mon Sep 17 00:00:00 2001 From: Meador Inge Date: Wed, 18 Feb 2015 18:34:59 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229716 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 2 -- test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp | 14 +++++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index d351b4841f..fd8b3e5431 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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; diff --git a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp index c23cd28f31..7d689ae0b1 100644 --- a/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp +++ b/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp @@ -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}} } -- 2.40.0