public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11684] New: Template specialisation
@ 2003-07-27 15:07 nickn at newsonnet dot fsnet dot co dot uk
2003-07-27 15:13 ` [Bug c++/11684] " pinskia at physics dot uc dot edu
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: nickn at newsonnet dot fsnet dot co dot uk @ 2003-07-27 15:07 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
Summary: Template specialisation
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nickn at newsonnet dot fsnet dot co dot uk
CC: gcc-bugs at gcc dot gnu dot org
The following example seems to instance the templated function incorrectly:
class test
{
public:
float operator[]( int index )
{
return testFloat[index];
}
private:
float testFloat[3];
};
template < class typeA > float
operator*(
typeA a,
float b
)
{
return a[0] * b;
}
template < class typeB > float
operator*(
float a,
typeB b
)
{
return a * b[0];
}
template < class typeA, class typeB > float
operator*(
typeA a,
typeB b
)
{
return a[0] * b[0];
}
int main( void )
{
test aTest;
float bTest;
float result;
result = aTest * bTest;
result = bTest * aTest;
return 0;
}
with the errors:
test.cpp:31: `float operator*(float, typeB) [with typeB = float]' must have
an argument of class or enumerated type
test.cpp:22: `float operator*(typeA, float) [with typeA = float]' must have
an argument of class or enumerated type
Surely if the operation is float * class the the more specialised template
is the float, typeB version, not the typeA, float version?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] Template specialisation
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
@ 2003-07-27 15:13 ` pinskia at physics dot uc dot edu
2003-07-30 1:25 ` pinskia at physics dot uc dot edu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-07-27 15:13 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
pinskia at physics dot uc dot edu changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |rejects-valid
Last reconfirmed|0000-00-00 00:00:00 |2003-07-27 15:13:29
date| |
------- Additional Comments From pinskia at physics dot uc dot edu 2003-07-27 15:13 -------
I can confirm this on the mainline (20030727), looks like gcc likes to pick the template based ones
rather than specialization ones (aka the ones builtin operator*(float, float)). This is not a
regression as 2.95.3 also reject this code.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] Template specialisation
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
2003-07-27 15:13 ` [Bug c++/11684] " pinskia at physics dot uc dot edu
@ 2003-07-30 1:25 ` pinskia at physics dot uc dot edu
2003-07-31 7:13 ` [Bug c++/11684] cannot find non-template (builtin) operator*(float,float) nickn at newsonnet dot fsnet dot co dot uk
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-07-30 1:25 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
------- Additional Comments From pinskia at physics dot uc dot edu 2003-07-30 01:25 -------
This passes with icc 6.0 with strict mode turned on (-Xc).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] cannot find non-template (builtin) operator*(float,float)
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
2003-07-27 15:13 ` [Bug c++/11684] " pinskia at physics dot uc dot edu
2003-07-30 1:25 ` pinskia at physics dot uc dot edu
@ 2003-07-31 7:13 ` nickn at newsonnet dot fsnet dot co dot uk
2003-08-19 19:04 ` mmitchel at gcc dot gnu dot org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: nickn at newsonnet dot fsnet dot co dot uk @ 2003-07-31 7:13 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
------- Additional Comments From nickn at newsonnet dot fsnet dot co dot uk 2003-07-31 07:13 -------
More than likely I don't quite understand the problem properly, but what's
wrong with gcc choosing the template based operator*? In the
expression "aTest * bTest", aTest is a class of type "test" whilst bTest is a
float. The problem, to me at least, is that it chooses the intrinsic type
(float) to represent the untyped variable in the template where as a better
match would be to match the float to the float and the test class to the
unknown type.
In the error (base on the aTest (class test) * bTest (float)):
test.cpp:31: `float operator*(float, typeB) [with typeB = float]' must have
an argument of class or enumerated type
surely it would have be fine if it'd choosen the other operator*(typeA,
float )?
Like I said - more than likely I don't understand the problem properly! :)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] cannot find non-template (builtin) operator*(float,float)
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
` (2 preceding siblings ...)
2003-07-31 7:13 ` [Bug c++/11684] cannot find non-template (builtin) operator*(float,float) nickn at newsonnet dot fsnet dot co dot uk
@ 2003-08-19 19:04 ` mmitchel at gcc dot gnu dot org
2003-08-20 7:07 ` cvs-commit at gcc dot gnu dot org
2003-08-20 7:13 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2003-08-19 19:04 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |mark at codesourcery dot com
|dot org |
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] cannot find non-template (builtin) operator*(float,float)
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
` (3 preceding siblings ...)
2003-08-19 19:04 ` mmitchel at gcc dot gnu dot org
@ 2003-08-20 7:07 ` cvs-commit at gcc dot gnu dot org
2003-08-20 7:13 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2003-08-20 7:07 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2003-08-20 07:06 -------
Subject: Bug 11684
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: mmitchel@gcc.gnu.org 2003-08-20 07:06:47
Modified files:
gcc : ChangeLog c-common.c convert.c
gcc/config/pa : pa.h
gcc/cp : ChangeLog class.c cp-tree.h decl.c decl2.c
name-lookup.c parser.c pt.c typeck2.c
gcc/testsuite : ChangeLog
gcc/testsuite/g++.dg/parse: typedef4.C
gcc/testsuite/g++.old-deja/g++.robertl: eb133.C eb133a.C
eb133b.C
gcc/testsuite/gcc.dg: c99-bool-1.c
Added files:
gcc/testsuite/g++.dg/expr: enum1.C
gcc/testsuite/g++.dg/parse: elab2.C operator4.C
gcc/testsuite/g++.dg/template: dtor2.C operator1.C
Log message:
PR c++/11946
* convert.c (convert_to_integer): Use CONVERT_EXPR (instead of
NOP_EXPR) when necessary.
* c-common.c (c_common_signed_or_unsigned_type): Correctly handle
types with precisions other than those given by native machine
modes.
PR c++/11684
* cp-tree.h (grok_op_properties): Change prototype.
* decl.c (grok_op_properties): Add complain parameter.
(grokfndecl): Pass it.
* pt.c (tsubst_decl): Adjust accordingly.
PR c++/10926
* decl.c (start_method): Return immediately if push_template_decl
does not like the declaration.
* pt.c (push_template_decl_real): Disallow member template
destructors.
PR c++/11036.C
* cp-tree.h (add_binding): Add prototype.
* class.c (add_method): Set TYPE_HAS_DESTRUCTOR if appropriate.
(maybe_warn_about_overly_private_class): Use
CLASSTYPE_DESTRUCTORS.
(pushclass): Adjust call to set_identifier_type_value.
* decl.c (add_binding): Give it external linkage.
(push_local_binding): Adjust call to add_binding.
(push_class_binding): Likewise.
(set_identifier_type_value_with_scope): Change prototype. Use
add_binding for global bindings.
(set_identifier_type_value): Adjust accordingly.
(pushtag): Likewise.
(pushdecl): Use set_identifier_type_value, not
set_identifier_type_value_with_scope.
(pushdecl_namespace_level): Adjust calls to
SET_IDENTIFIER_TYPE_VALUE to pass a DECL.
(pushdecl_class_level): Likewise.
(lookup_tag): Use select_decl.
(select_decl): Improve comment.
(record_builtin_type): Do not call pushdecl.
(cxx_init_decl_processing): Do not call xref_tag for bad_alloc.
(cp_finish_decl): Adjust call to set_identifier_type_value.
(check_elaborated_type_specifier): Improve checks for invalid uses
of typedefs.
(xref_tag): Adjust call to check_elaborated_type_specifier.
* decl2.c (grokclassfn): Do not set TYPE_HAS_DESTRUCTOR.
* name-lookup.c (set_namespace_binding): Use add_binding.
* parser.c (cp_parser_simple_type_specifier): Return a TYPE_DECL,
rather than an IDENTIFIER_NODE, to represent built-in types, if
requested by the caller.
(cp_parser_postfix_expression): Adjust call.
(cp_parser_type_specifier): Likewise.
(cp_parser_elaborated_type_specifier): Adjust call to
check_elaborated_type_specifier.
* typeck2.c (build_functional_cast): Do not perform name lookups.
PR c++/10717
* decl.c (expand_static_init): Remove unncessary code.
PR c++/10926
* g++.dg/template/dtor2.C: New test.
PR c++/11684
* g++.dg/template/operator1.C: New test.
* g++.dg/parse/operator4.C: New test.
PR c++/11946.C
* g++.dg/expr/enum1.C: New test.
* gcc.dg/c99-bool-1.c: Remove bogus warning.
PR c++/11036.C
* g++.dg/parse/elab2.C: New test.
* g++.dg/parse/typedef4.C: Change error message.
* g++.old-deja/g++.robertl/eb133.C: Remove bogus error markers.
* g++.old-deja/g++.robertl/eb133a.C: Remove bogus error markers.
* g++.old-deja/g++.robertl/eb133b.C: Remove bogus error markers.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.812&r2=2.813
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.c.diff?cvsroot=gcc&r1=1.448&r2=1.449
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/convert.c.diff?cvsroot=gcc&r1=1.32&r2=1.33
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/pa/pa.h.diff?cvsroot=gcc&r1=1.200&r2=1.201
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3610&r2=1.3611
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.563&r2=1.564
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.903&r2=1.904
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1113&r2=1.1114
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.661&r2=1.662
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.8&r2=1.9
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.101&r2=1.102
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.760&r2=1.761
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck2.c.diff?cvsroot=gcc&r1=1.147&r2=1.148
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2981&r2=1.2982
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/enum1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/elab2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/operator4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/typedef4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/dtor2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133.C.diff?cvsroot=gcc&r1=1.7&r2=1.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133a.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb133b.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/c99-bool-1.c.diff?cvsroot=gcc&r1=1.3&r2=1.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/11684] cannot find non-template (builtin) operator*(float,float)
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
` (4 preceding siblings ...)
2003-08-20 7:07 ` cvs-commit at gcc dot gnu dot org
@ 2003-08-20 7:13 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2003-08-20 7:13 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11684
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
------- Additional Comments From mmitchel at gcc dot gnu dot org 2003-08-20 07:13 -------
Fixed in GCC 3.4.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-08-20 7:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-27 15:07 [Bug c++/11684] New: Template specialisation nickn at newsonnet dot fsnet dot co dot uk
2003-07-27 15:13 ` [Bug c++/11684] " pinskia at physics dot uc dot edu
2003-07-30 1:25 ` pinskia at physics dot uc dot edu
2003-07-31 7:13 ` [Bug c++/11684] cannot find non-template (builtin) operator*(float,float) nickn at newsonnet dot fsnet dot co dot uk
2003-08-19 19:04 ` mmitchel at gcc dot gnu dot org
2003-08-20 7:07 ` cvs-commit at gcc dot gnu dot org
2003-08-20 7:13 ` mmitchel 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).