aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2015-07-17 22:37:31 +0000
committerBrooks Moses <bmoses@google.com>2015-07-17 22:37:31 +0000
commitdc63b6e16c558416029cb9d9cb4dfea2a1869fd8 (patch)
treef118db2eb24aa6365d49dd4f584c298b4a5c26ae
parent0ad4f56c25eccbee4959773102e4b44f8be3a21b (diff)
Backport r216258 to google/gcc-4_9 branch.
2014-10-15 Jonathan Wakely <jwakely@redhat.com> * include/std/complex (complex::real, complex::imag): Add const. * testsuite/26_numerics/complex/value_operations/constexpr2.cc: New. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/google/gcc-4_9@225972 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libstdc++-v3/include/std/complex4
-rw-r--r--libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr2.cc29
2 files changed, 31 insertions, 2 deletions
diff --git a/libstdc++-v3/include/std/complex b/libstdc++-v3/include/std/complex
index 3104b584eb6..3f98505f730 100644
--- a/libstdc++-v3/include/std/complex
+++ b/libstdc++-v3/include/std/complex
@@ -147,11 +147,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// DR 387. std::complex over-encapsulated.
_GLIBCXX_ABI_TAG_CXX11
constexpr _Tp
- real() { return _M_real; }
+ real() const { return _M_real; }
_GLIBCXX_ABI_TAG_CXX11
constexpr _Tp
- imag() { return _M_imag; }
+ imag() const { return _M_imag; }
#else
/// Return real part of complex number.
_Tp&
diff --git a/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr2.cc b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr2.cc
new file mode 100644
index 00000000000..9f157d37b00
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr2.cc
@@ -0,0 +1,29 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++14" }
+
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <complex>
+
+int main()
+{
+ constexpr std::complex<int> c{};
+ constexpr auto r __attribute__((unused)) = real(c);
+ constexpr auto i __attribute__((unused)) = imag(c);
+}
+