This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

std::complex<>::__rep() uses wrong CONSTEXPR macro


When constexpr support was added the complex<>::__rep() member changed
from returning a const-reference to returning by value, like so:

@@ -215,7 +215,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       template<typename _Up>
         complex<_Tp>& operator/=(const complex<_Up>&);

-      const complex& __rep() const
+      _GLIBCXX_USE_CONSTEXPR complex __rep() const
       { return *this; }

     private:


In C++11 mode that expands to a constexpr function returning a
complex, but in C++03 mode it expands to a function returning const
complex. I think that difference is accidental, and it should use
_GLIBCXX_CONSTEXPR so it returns a non-const complex in both modes.

This case is clearer, in complex<float>:

@@ -1170,7 +1167,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
          return *this;
        }

-      const _ComplexT& __rep() const { return _M_value; }
+      _GLIBCXX_USE_CONSTEXPR _ComplexT __rep() const { return _M_value; }

     private:
       _ComplexT _M_value;

Here we return a const _ComplexT in C++03, which is a scalar type so
the const is ignored (and gives a warning with -Wignored-qualifiers).

I don't think the const is there intentionally, so I plan to change
them to use _GLIBCXX_CONSTEXPR instead, as shown in the attached
patch.

Attachment: p.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]