public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35146] New: weird error in template function specialization
@ 2008-02-09 1:41 grey_earl at web dot de
2008-02-09 1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: grey_earl at web dot de @ 2008-02-09 1:41 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2590 bytes --]
gcc -v:
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr
--disable-libmudflap --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 20080114 (prerelease) (Debian 4.2.2-7)
The error:
schroed2.cpp: In function âvoid blas_scal(typename ref<R>::result,
complex<T>*) [with T = double]â:
schroed2.cpp:16: error: cannot convert âcomplex<double>â to âdoubleâ
for argument â1â to âvoid cblas_zdscal(double, void*)â
The code:
template <typename T> struct complex { T re; T im; };
template <typename R> struct ref { typedef const R& result; };
template <> struct ref<double> { typedef double result; };
template <> struct ref<complex<double> > { typedef complex<double> result; };
void cblas_dscal(double alpha, double *x) { }
void cblas_zscal(void *alpha, void *x) { }
void cblas_zdscal(double alpha, void *x) { }
template <typename T> void blas_scal(typename ref<T>::result alpha, T* x);
template <typename T> void blas_scal(typename ref<T>::result alpha, complex<T>*
x);
template <> void blas_scal(double alpha, double* x) { cblas_dscal(alpha, x); }
template <> void blas_scal(complex<double> alpha, complex<double>* x) {
complex<double> cblas_alpha = alpha; cblas_zscal(&cblas_alpha, x); }
template <> void blas_scal(double alpha, complex<double>* x) {
cblas_zdscal(alpha, x); } // line 16 is here
int main() {
return 0;
}
The ref-struct allows to use pass-by-reference for big datatypes, pass-by-value
for small ones. If I replace this struct in the template declaration for
blas_scal by T, everything works as expected. For T = double, the last
specialization is imho valid for the second template declaration - I don't even
know what gcc wants from me, since the parameters are exactly what is needed.
--
Summary: weird error in template function specialization
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: grey_earl at web dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
@ 2008-02-09 1:45 ` pinskia at gcc dot gnu dot org
2008-02-10 1:13 ` [Bug c++/35146] [4.1/4.2 regression] " bangerth at dealii dot org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-02-09 1:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-02-09 01:45 -------
This works fine on the trunk.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.1/4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
2008-02-09 1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
@ 2008-02-10 1:13 ` bangerth at dealii dot org
2008-02-10 23:07 ` rguenth at gcc dot gnu dot org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: bangerth at dealii dot org @ 2008-02-10 1:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from bangerth at dealii dot org 2008-02-10 01:13 -------
Confirmed. This was introduced in 3.4.x, and worked before. As Andrew
already noted, this has been fixed in mainline.
The problem can be more succinctly shown by the following testcase:
--------------------
template <typename T> struct S {};
template <typename R> struct ref;
template <> struct ref<double> { typedef double result; };
template <typename T> void foo(typename ref<T>::result, S<T>*);
template <> void foo(S<double>, S<double>*);
template <> void foo(double alpha, S<double>* x)
{
alpha; x;
}
-----------------------
g/x> c++-4.2.1 -S x.cc
x.cc: In function 'void foo(typename ref<R>::result, S<T>*) [with T = double]':
x.cc:10: error: 'alpha' was not declared in this scope
x.cc:10: error: 'x' was not declared in this scope
What is happening is that we are looking up the parameters from the wrong
declaration. The function in question on line 10 of course has them
declared and named, but we are looking at the specialization in line 7:
if the parameters are named there, then the code compiles. However, as
shown in the original testcase, the parameters then have the wrong
type.
It shouldn't be too hard to construct a case where this produces wrong
code.
Can someone determine whether this is still wrong with the released
4.2.3? I consider this a particularly heinous bug since it's almost
impossible to see in a real code where the error is coming from (if
we get one) or why the produced code is wrong.
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Known to fail| |4.2.1 4.1.2 4.0.4 3.4.6
Known to work|4.3.0 |4.3.0 3.3.6
Last reconfirmed|0000-00-00 00:00:00 |2008-02-10 01:13:11
date| |
Summary|weird error in template |[4.1/4.2 regression] weird
|function specialization |error in template function
| |specialization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.1/4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
2008-02-09 1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
2008-02-10 1:13 ` [Bug c++/35146] [4.1/4.2 regression] " bangerth at dealii dot org
@ 2008-02-10 23:07 ` rguenth at gcc dot gnu dot org
2008-02-11 3:38 ` bangerth at dealii dot org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-02-10 23:07 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from rguenth at gcc dot gnu dot org 2008-02-10 23:06 -------
While the original testcase works for me on trunk, the testcase in comment #2
does
not. Or am I missing sth?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.1/4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (2 preceding siblings ...)
2008-02-10 23:07 ` rguenth at gcc dot gnu dot org
@ 2008-02-11 3:38 ` bangerth at dealii dot org
2008-02-15 17:12 ` grey_earl at web dot de
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: bangerth at dealii dot org @ 2008-02-11 3:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bangerth at dealii dot org 2008-02-11 03:38 -------
(In reply to comment #3)
> While the original testcase works for me on trunk, the testcase in comment #2
> does
> not. Or am I missing sth?
I see the same behavior with yesterday's svn version. The testcase in
comment #2 is definitely valid, so we still have a regression.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.1/4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (3 preceding siblings ...)
2008-02-11 3:38 ` bangerth at dealii dot org
@ 2008-02-15 17:12 ` grey_earl at web dot de
2008-03-27 22:24 ` rguenth at gcc dot gnu dot org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: grey_earl at web dot de @ 2008-02-15 17:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from grey_earl at web dot de 2008-02-15 17:12 -------
Both testcases fail with 4.2.3 release version, with exactly the same errors.
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--disable-libmudflap --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Debian 4.2.3-1)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.1/4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (4 preceding siblings ...)
2008-02-15 17:12 ` grey_earl at web dot de
@ 2008-03-27 22:24 ` rguenth at gcc dot gnu dot org
2008-07-04 22:34 ` [Bug c++/35146] [4.2 " jsm28 at gcc dot gnu dot org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-03-27 22:24 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.1.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.2 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (5 preceding siblings ...)
2008-03-27 22:24 ` rguenth at gcc dot gnu dot org
@ 2008-07-04 22:34 ` jsm28 at gcc dot gnu dot org
2009-03-31 15:10 ` [Bug c++/35146] [4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-07-04 22:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from jsm28 at gcc dot gnu dot org 2008-07-04 22:33 -------
Closing 4.1 branch.
--
jsm28 at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[4.1/4.2 regression] weird |[4.2 regression] weird error
|error in template function |in template function
|specialization |specialization
Target Milestone|4.1.3 |4.2.5
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (6 preceding siblings ...)
2008-07-04 22:34 ` [Bug c++/35146] [4.2 " jsm28 at gcc dot gnu dot org
@ 2009-03-31 15:10 ` jsm28 at gcc dot gnu dot org
2009-04-06 20:15 ` jason at gcc dot gnu dot org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2009-03-31 15:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from jsm28 at gcc dot gnu dot org 2009-03-31 15:10 -------
Closing 4.2 branch, original test fixed in 4.3. However, there's a note here
about the test in comment#2 being valid and failing on trunk as of a year
ago, and that test does still fail, so marking as a 4.3/4.4/4.5 regression
instead of closing.
(I have not tried to check if the test in comment#2 is indeed valid, or if
it is indeed a regression from some previous version.)
--
jsm28 at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|4.2.1 4.1.2 4.0.4 3.4.6 |4.2.1 4.1.2 4.0.4 3.4.6
| |4.2.5
Known to work|4.3.0 3.3.6 |3.3.6
Last reconfirmed|2008-02-10 01:13:11 |2009-03-31 15:10:20
date| |
Summary|[4.2 regression] weird error|[4.3/4.4/4.5 regression]
|in template function |weird error in template
|specialization |function specialization
Target Milestone|4.2.5 |4.3.4
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (7 preceding siblings ...)
2009-03-31 15:10 ` [Bug c++/35146] [4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
@ 2009-04-06 20:15 ` jason at gcc dot gnu dot org
2009-04-06 20:29 ` jason at gcc dot gnu dot org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-06 20:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from jason at gcc dot gnu dot org 2009-04-06 20:14 -------
The testcase in comment #2 is ill-formed;
template <> void foo(S<double>, S<double>*);
is not a specialization of any function template in scope. But we're giving
very much the wrong error for that. Testing a patch now.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jason at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2009-03-31 15:10:20 |2009-04-06 20:14:50
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (8 preceding siblings ...)
2009-04-06 20:15 ` jason at gcc dot gnu dot org
@ 2009-04-06 20:29 ` jason at gcc dot gnu dot org
2009-04-06 20:55 ` jason at gcc dot gnu dot org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-06 20:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from jason at gcc dot gnu dot org 2009-04-06 20:29 -------
...and GCC miscompiles the original testcase due to the same bug.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (9 preceding siblings ...)
2009-04-06 20:29 ` jason at gcc dot gnu dot org
@ 2009-04-06 20:55 ` jason at gcc dot gnu dot org
2009-04-06 21:35 ` jason at gcc dot gnu dot org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-06 20:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from jason at gcc dot gnu dot org 2009-04-06 20:55 -------
Subject: Bug 35146
Author: jason
Date: Mon Apr 6 20:55:04 2009
New Revision: 145625
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145625
Log:
PR c++/35146
* pt.c (fn_type_unification): For DEDUCE_EXACT check that
the deduced template arguments give us the parameter types
we're looking for.
Added:
trunk/gcc/testsuite/g++.dg/template/fnspec1.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (10 preceding siblings ...)
2009-04-06 20:55 ` jason at gcc dot gnu dot org
@ 2009-04-06 21:35 ` jason at gcc dot gnu dot org
2009-04-07 3:51 ` jason at gcc dot gnu dot org
2009-04-07 4:46 ` jason at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-06 21:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from jason at gcc dot gnu dot org 2009-04-06 21:35 -------
Subject: Bug 35146
Author: jason
Date: Mon Apr 6 21:35:29 2009
New Revision: 145634
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145634
Log:
PR c++/35146
* pt.c (fn_type_unification): For DEDUCE_EXACT check that
the deduced template arguments give us the parameter types
we're looking for.
Added:
branches/gcc-4_4-branch/gcc/testsuite/g++.dg/template/fnspec1.C
Modified:
branches/gcc-4_4-branch/gcc/cp/ChangeLog
branches/gcc-4_4-branch/gcc/cp/pt.c
branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (11 preceding siblings ...)
2009-04-06 21:35 ` jason at gcc dot gnu dot org
@ 2009-04-07 3:51 ` jason at gcc dot gnu dot org
2009-04-07 4:46 ` jason at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-07 3:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from jason at gcc dot gnu dot org 2009-04-07 03:51 -------
Subject: Bug 35146
Author: jason
Date: Tue Apr 7 03:50:49 2009
New Revision: 145647
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145647
Log:
PR c++/35146
* pt.c (fn_type_unification): For DEDUCE_EXACT check that
the deduced template arguments give us the parameter types
we're looking for.
Added:
branches/gcc-4_3-branch/gcc/testsuite/g++.dg/template/fnspec1.C
Modified:
branches/gcc-4_3-branch/gcc/cp/ChangeLog
branches/gcc-4_3-branch/gcc/cp/pt.c
branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/35146] [4.3/4.4/4.5 regression] weird error in template function specialization
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
` (12 preceding siblings ...)
2009-04-07 3:51 ` jason at gcc dot gnu dot org
@ 2009-04-07 4:46 ` jason at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-04-07 4:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #13 from jason at gcc dot gnu dot org 2009-04-07 04:46 -------
Fixed.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35146
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2009-04-07 4:46 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-09 1:41 [Bug c++/35146] New: weird error in template function specialization grey_earl at web dot de
2008-02-09 1:45 ` [Bug c++/35146] " pinskia at gcc dot gnu dot org
2008-02-10 1:13 ` [Bug c++/35146] [4.1/4.2 regression] " bangerth at dealii dot org
2008-02-10 23:07 ` rguenth at gcc dot gnu dot org
2008-02-11 3:38 ` bangerth at dealii dot org
2008-02-15 17:12 ` grey_earl at web dot de
2008-03-27 22:24 ` rguenth at gcc dot gnu dot org
2008-07-04 22:34 ` [Bug c++/35146] [4.2 " jsm28 at gcc dot gnu dot org
2009-03-31 15:10 ` [Bug c++/35146] [4.3/4.4/4.5 " jsm28 at gcc dot gnu dot org
2009-04-06 20:15 ` jason at gcc dot gnu dot org
2009-04-06 20:29 ` jason at gcc dot gnu dot org
2009-04-06 20:55 ` jason at gcc dot gnu dot org
2009-04-06 21:35 ` jason at gcc dot gnu dot org
2009-04-07 3:51 ` jason at gcc dot gnu dot org
2009-04-07 4:46 ` jason at gcc dot gnu dot 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).