aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-11-01 21:31:50 -0400
committerJason Merrill <jason@gcc.gnu.org>2010-11-01 21:31:50 -0400
commit900484dee595d91a71c7ae63734c199bd137afc6 (patch)
treea81889fc318d20d599750c915656f1365ed5f443
parent2bfe0527cd744a6f526fe11dd6c11ab39ad0a653 (diff)
downloadgcc-900484dee595d91a71c7ae63734c199bd137afc6.zip
gcc-900484dee595d91a71c7ae63734c199bd137afc6.tar.gz
gcc-900484dee595d91a71c7ae63734c199bd137afc6.tar.bz2
initializer_list: Decorate with constexpr.
* libsupc++/initializer_list: Decorate with constexpr. Co-Authored-By: Benjamin Kosnik <bkoz@redhat.com> From-SVN: r166170
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C10
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C12
-rw-r--r--libstdc++-v3/ChangeLog4
-rw-r--r--libstdc++-v3/libsupc++/initializer_list20
5 files changed, 39 insertions, 10 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 90aca237..8fc1d6b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,9 @@
2010-11-01 Jason Merrill <jason@redhat.com>
Benjamin Kosnik <bkoz@redhat.com>
+ * g++.dg/cpp0x/constexpr-initlist2.C: New.
+ * g++.dg/cpp0x/constexpr-initlist3.C: New.
+
* g++.dg/cpp0x/constexpr-array-ptr.C: New.
* g++.dg/cpp0x/constexpr-array-ptr2.C: New.
* g++.dg/cpp0x/constexpr-array-ptr3.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C
new file mode 100644
index 0000000..f34b980
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist2.C
@@ -0,0 +1,10 @@
+// { dg-options -std=c++0x }
+
+#include <initializer_list>
+
+constexpr auto list = { 1, 2, 3, 4 };
+
+#define SA(X) static_assert(X, #X)
+SA(list.size() == 4);
+SA(list.begin()[2] == 3);
+SA(list.end()[-1] == 4);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C
new file mode 100644
index 0000000..7620e6b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist3.C
@@ -0,0 +1,12 @@
+// { dg-options -std=c++0x }
+
+#include <initializer_list>
+#define SA(X) static_assert(X,#X)
+
+constexpr int f(std::initializer_list<int> l) { return l.begin()[0]; }
+
+int main()
+{
+ constexpr int i = f({42});
+ SA(i==42);
+}
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 39f5325..510bc4e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-01 Jason Merrill <jason@redhat.com>
+
+ * libsupc++/initializer_list: Decorate with constexpr.
+
2010-11-01 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/45999
diff --git a/libstdc++-v3/libsupc++/initializer_list b/libstdc++-v3/libsupc++/initializer_list
index 0006b70..1048d44 100644
--- a/libstdc++-v3/libsupc++/initializer_list
+++ b/libstdc++-v3/libsupc++/initializer_list
@@ -57,23 +57,23 @@ namespace std
size_type _M_len;
// The compiler can call a private constructor.
- initializer_list(const_iterator __a, size_type __l)
+ constexpr initializer_list(const_iterator __a, size_type __l)
: _M_array(__a), _M_len(__l) { }
public:
- initializer_list() : _M_array(0), _M_len(0) { }
+ constexpr initializer_list() : _M_array(0), _M_len(0) { }
// Number of elements.
- size_type
- size() const { return _M_len; }
+ constexpr size_type
+ size() { return _M_len; }
// First element.
- const_iterator
- begin() const { return _M_array; }
+ constexpr const_iterator
+ begin() { return _M_array; }
// One past the last element.
- const_iterator
- end() const { return begin() + size(); }
+ constexpr const_iterator
+ end() { return begin() + size(); }
};
/**
@@ -82,7 +82,7 @@ namespace std
* @param il Initializer list.
*/
template<class _Tp>
- inline const _Tp*
+ constexpr const _Tp*
begin(initializer_list<_Tp> __ils)
{ return __ils.begin(); }
@@ -92,7 +92,7 @@ namespace std
* @param il Initializer list.
*/
template<class _Tp>
- inline const _Tp*
+ constexpr const _Tp*
end(initializer_list<_Tp> __ils)
{ return __ils.end(); }
}