[LLVMbugs] [Bug 20293] New: The return type of std::pow(std::complex<float>, int) should be std::complex<float>
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Jul 14 00:18:53 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20293
Bug ID: 20293
Summary: The return type of std::pow(std::complex<float>, int)
should be std::complex<float>
Product: libc++
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: kariya_mitsuru at hotmail.com
CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
Classification: Unclassified
With libc++, the return type of std::pow(std::complex<float>, int) is
std::complex<double>.
However, in C++03 mode, the return type of std::pow(std::complex<float>, int)
should be
std::complex<float>.
According to C++03 standard 26.2.7[lib.complex.value.ops], std::pow have an
overload
function template "template<class T> std::complex<T> std::pow(const
std::complex<T>&, int)".
So I think that the return type of std::pow(std::complex<float>, int) should be
std::complex<float> in C++03 mode.
The sample code below can show whether the return type is std::complex<float>.
===========================================================================================
#include <iostream>
#include <typeinfo>
#include <complex>
int main()
{
std::cout << std::boolalpha
<< (typeid(std::pow(std::complex<float>(1), 1)) ==
typeid(std::complex<float>))
<< std::endl;
}
===========================================================================================
cf. http://melpon.org/wandbox/permlink/GT7RQffV1BXEOImC
Additionally, in C++03, the 2nd argument of std::pow can cause implicit
conversions.
(Because it is the trivial int type.)
Therefore, I think that the sample code below should be compiled successfully
in C++03 mode.
===========================================================================================
#include <complex>
struct S {
operator int() { return 1; }
};
int main()
{
std::complex<float> d = std::pow(std::complex<float>(0), S());
}
===========================================================================================
cf. http://melpon.org/wandbox/permlink/G0CEVjhnaTEMfbNs
Note that the 2nd sample should be compiled successfully with double and long
double too.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140714/51dee730/attachment.html>
More information about the llvm-bugs
mailing list