public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/61795] New: [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double>
@ 2014-07-13 17:55 kariya_mitsuru at hotmail dot com
2014-07-13 18:29 ` [Bug libstdc++/61795] " daniel.kruegler at googlemail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-07-13 17:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61795
Bug ID: 61795
Summary: [C++11] return type of std::pow(std::complex<float>,
int) should be std::complex<double>
Product: gcc
Version: 4.10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: kariya_mitsuru at hotmail dot com
With libstdc++, the return type of std::pow(std::complex<float>, int) is
std::complex<float>.
However, In C++11 mode, the return type of std::pow(std::complex<float>, int)
should be std::complex<double>.
According to C++11 standard 26.4.9[cmplx.over] paragraph 3, "if either argument
has type complex<double>, double, or an integer type, then both arguments are
effectively cast to complex<double>."
The return type of std::pow(std::complex<double>, std::complex<double>) is
std::complex<double>, So I think that std::pow(std::complex<float>, int) should
be std::complex<double> in C++11 mode.
The sample code below can show whether the return type is std::complex<double>.
================================================================================
#include <iostream>
#include <typeinfo>
#include <complex>
int main()
{
std::cout << std::boolalpha
<< (typeid(std::pow(std::complex<float>(1), 1)) ==
typeid(std::complex<double>))
<< std::endl;
}
================================================================================
cf. http://melpon.org/wandbox/permlink/zW8TWZe9kKzKWqFq
While in C++03 mode, the return type of std::pow(std::complex<float>, int)
should be std::complex<float>, I think.
Note that this problem does not occur in std::complex<double> and
std::complex<long double> because there is no difference between C++03 and
C++11.
See also: PR56106, PR57974
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/61795] [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double>
2014-07-13 17:55 [Bug libstdc++/61795] New: [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double> kariya_mitsuru at hotmail dot com
@ 2014-07-13 18:29 ` daniel.kruegler at googlemail dot com
2014-07-14 3:41 ` kariya_mitsuru at hotmail dot com
2015-04-09 15:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2014-07-13 18:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61795
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler@googlemail.
| |com
--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
I agree with your analysis. I believe that the observed behaviour is due to a
lack of applying yet the corresponding library defect
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#844
to libstdc++, because in an earlier working draft there was the required
overload:
template<class T> complex<T> pow(const complex<T>& x, int y);
which had lead to the observed result.
>From gcc-bugs-return-456232-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Jul 13 18:37:34 2014
Return-Path: <gcc-bugs-return-456232-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 2195 invoked by alias); 13 Jul 2014 18:37:34 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 1909 invoked by uid 48); 13 Jul 2014 18:37:30 -0000
From: "anlauf at gmx dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/61615] Failure to resolve correct generic with TYPE(C_PTR) arguments
Date: Sun, 13 Jul 2014 18:37:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: fortran
X-Bugzilla-Version: 4.10.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: anlauf at gmx dot de
X-Bugzilla-Status: WAITING
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-61615-4-4iRxVJ52Vm@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61615-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61615-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-07/txt/msg00823.txt.bz2
Content-length: 723
https://gcc.gnu.org/bugzilla/show_bug.cgi?ida615
--- Comment #7 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Dominique d'Humieres from comment #6)
Well, the problem is in the resolution of the generic,
not in the invocation in the main.
If you comment out
! MODULE PROCEDURE bar_a1d
you get the result desired by the author:
in bar_s
Now if you comment out the module procedure bar_s,
gfortran does *not* complain, but resolve to the *wrong* procedure.
So for some strange reason, gfortran fails to recognise the proper rank.
OTOH, NAG complains:
Error: pr61615.f90, line 28: No specific match for reference to generic BAR
I get corresponding errors from PGI or Intel.
IMO a bug in gfortran.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/61795] [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double>
2014-07-13 17:55 [Bug libstdc++/61795] New: [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double> kariya_mitsuru at hotmail dot com
2014-07-13 18:29 ` [Bug libstdc++/61795] " daniel.kruegler at googlemail dot com
@ 2014-07-14 3:41 ` kariya_mitsuru at hotmail dot com
2015-04-09 15:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-07-14 3:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61795
--- Comment #2 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
I think that this behaviour is caused by r201253 (for PR57974, Comment 11).
DR844 was fixed by r136694 but reverted by r201253.
diff r135878 r136694
https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/std/complex?r1=135878&r2=136694
diff r199924 r201253
https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/include/std/complex?r1=199924&r2=201253
Moreover, I think that I mistook.
> Note that this problem does not occur in std::complex<double> and
> std::complex<long double> because there is no difference between
> C++03 and C++11.
This is not true.
In C++03, the 2nd argument of std::pow can cause implicit conversions.
(Because it is the trivial int type.)
However, I believe that it should cause no implicit conversion in C++11.
(I think so from C++11 standard text quoted above.)
Therefore, I think that the sample code below should be compiled successfully
in C++03 mode but should cause compilation error in C++11 mode.
===================================================================
#include <complex>
struct S {
operator int() { return 1; }
};
int main()
{
std::complex<double> d = std::pow(std::complex<double>(0), S());
}
===================================================================
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug libstdc++/61795] [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double>
2014-07-13 17:55 [Bug libstdc++/61795] New: [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double> kariya_mitsuru at hotmail dot com
2014-07-13 18:29 ` [Bug libstdc++/61795] " daniel.kruegler at googlemail dot com
2014-07-14 3:41 ` kariya_mitsuru at hotmail dot com
@ 2015-04-09 15:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2015-04-09 15:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61795
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2015-04-09
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-04-09 15:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-13 17:55 [Bug libstdc++/61795] New: [C++11] return type of std::pow(std::complex<float>, int) should be std::complex<double> kariya_mitsuru at hotmail dot com
2014-07-13 18:29 ` [Bug libstdc++/61795] " daniel.kruegler at googlemail dot com
2014-07-14 3:41 ` kariya_mitsuru at hotmail dot com
2015-04-09 15:43 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).