From dc63b6e16c558416029cb9d9cb4dfea2a1869fd8 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 17 Jul 2015 22:37:31 +0000 Subject: Backport r216258 to google/gcc-4_9 branch. 2014-10-15 Jonathan Wakely * 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 --- libstdc++-v3/include/std/complex | 4 +-- .../complex/value_operations/constexpr2.cc | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/26_numerics/complex/value_operations/constexpr2.cc 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 +// . + +#include + +int main() +{ + constexpr std::complex c{}; + constexpr auto r __attribute__((unused)) = real(c); + constexpr auto i __attribute__((unused)) = imag(c); +} + -- cgit v1.2.3