complex (complex::real, [...]): Add const.

* include/std/complex (complex::real, complex::imag): Add const.
	* testsuite/26_numerics/complex/value_operations/constexpr2.cc: New.

From-SVN: r216258
This commit is contained in:
Jonathan Wakely 2014-10-15 14:20:12 +01:00 committed by Jonathan Wakely
parent cd9b223aaa
commit 327a79a523
3 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,8 @@
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.
2014-10-15 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/limits: Remove stray semicolon.

View File

@ -144,11 +144,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&

View File

@ -0,0 +1,28 @@
// { 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);
}