public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008
@ 2009-10-14 5:52 DimanNe at ya dot ru
2009-10-14 9:11 ` [Bug c++/41703] " redi at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: DimanNe at ya dot ru @ 2009-10-14 5:52 UTC (permalink / raw)
To: gcc-bugs
Hello! I have FreeBSD 8.0-BETA4.
Why this
#include <iostream>
template <typename T, unsigned int (T::*)() const>
class TSizeEnabler { public: typedef T TClass; };
template <typename X> unsigned int GetAllSize(const X &Var)
{ return sizeof(Var); }
template <typename X> unsigned int GetAllSize(const typename TSizeEnabler<X,
&X::CalcMySize>::TClass &Var)
{ return Var.CalcMySize(); }
template <typename T>
class THash
{
public:
T Var;
unsigned int CalcMySize() const { return 42 + GetAllSize<T>(Var); }
};
int main()
{
int a;
THash<int> b;
std::cout << GetAllSize<int>(a) << std::endl;
std::cout << GetAllSize< THash<int> >(b) << std::endl;
return 0;
}
works well at gcc 3.4.6 but fails at gcc 4.2.1 and gcc 4.5.0.20091008 with
these messages:
gcc 4.5.0.2009100 output:
%g++45 -std=c++0x main.cpp
main.cpp: In function 'int main()':
main.cpp:24:46: error: call of overloaded 'GetAllSize(THash<int>&)' is
ambiguous
main.cpp:6:36: note: candidates are: unsigned int GetAllSize(const X&) [with X
= THash<int>]
main.cpp:8:36: note: unsigned int GetAllSize(const typename TSizeEnabler<X, (&
X::CalcMySize)>::TClass&) [with X = THash<int>, typename TSizeEnabler<X, (&
X::CalcMySize)>::TClass = THash<int>]
%
And gcc 4.2.1 output:
%g++ main.cpp
main.cpp: In function 'int main()':
main.cpp:23: error: call of overloaded 'GetAllSize(THash<int>&)' is ambiguous
main.cpp:5: note: candidates are: unsigned int GetAllSize(const X&) [with X =
THash<int>]
main.cpp:7: note: unsigned int GetAllSize(const typename
TSizeEnabler<X, (& X::CalcMySize)>::TClass&) [with X = THash<int>]
%
And how i can fix it the problem?
Thanks.
--
Summary: Problems with SFINAE. Source works at gcc 3.4.6 but
fails at 4.2.1 and 4.5.0.20091008
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: DimanNe at ya dot ru
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/41703] Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008
2009-10-14 5:52 [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008 DimanNe at ya dot ru
@ 2009-10-14 9:11 ` redi at gcc dot gnu dot org
2009-11-05 18:41 ` jason at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-10-14 9:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from redi at gcc dot gnu dot org 2009-10-14 09:10 -------
Slightly reduced:
template <typename T, int (T::*)() const>
struct TSizeEnabler
{
typedef T TClass;
};
template <typename X>
int
GetAllSize(const X &Var)
{ return sizeof(Var); }
template <typename X>
int
GetAllSize(const typename TSizeEnabler<X, &X::func>::TClass &Var)
{ return Var.func(); }
struct H
{
int func() const;
};
int main()
{
H b;
return GetAllSize< H >(b);
}
I think you're right that this is a bug. As a workaround you might be able to
remove GetAllSize(const X &Var) from the overload set for the case when
X::CalcMySize exists.
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jwakely dot gcc at gmail dot
| |com
Known to fail| |4.1.2 4.4.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/41703] Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008
2009-10-14 5:52 [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008 DimanNe at ya dot ru
2009-10-14 9:11 ` [Bug c++/41703] " redi at gcc dot gnu dot org
@ 2009-11-05 18:41 ` jason at gcc dot gnu dot org
2009-11-06 3:33 ` jason at gcc dot gnu dot org
2009-11-06 4:10 ` jason at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-05 18:41 UTC (permalink / raw)
To: gcc-bugs
--
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|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-11-05 18:41:37
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/41703] Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008
2009-10-14 5:52 [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008 DimanNe at ya dot ru
2009-10-14 9:11 ` [Bug c++/41703] " redi at gcc dot gnu dot org
2009-11-05 18:41 ` jason at gcc dot gnu dot org
@ 2009-11-06 3:33 ` jason at gcc dot gnu dot org
2009-11-06 4:10 ` jason at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-06 3:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jason at gcc dot gnu dot org 2009-11-06 03:33 -------
Subject: Bug 41703
Author: jason
Date: Fri Nov 6 03:32:55 2009
New Revision: 153957
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153957
Log:
PR c++/41703
* pt.c (check_undeduced_parms): New subroutine of...
(more_specialized_fn): ...here. Undeduced template parms can make
a template less specialized than another.
Added:
trunk/gcc/testsuite/g++.dg/template/partial6.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/41703] Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008
2009-10-14 5:52 [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008 DimanNe at ya dot ru
` (2 preceding siblings ...)
2009-11-06 3:33 ` jason at gcc dot gnu dot org
@ 2009-11-06 4:10 ` jason at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-11-06 4:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from jason at gcc dot gnu dot org 2009-11-06 04:10 -------
Fixed for 4.5.
--
jason at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.5.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41703
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-06 4:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-14 5:52 [Bug c++/41703] New: Problems with SFINAE. Source works at gcc 3.4.6 but fails at 4.2.1 and 4.5.0.20091008 DimanNe at ya dot ru
2009-10-14 9:11 ` [Bug c++/41703] " redi at gcc dot gnu dot org
2009-11-05 18:41 ` jason at gcc dot gnu dot org
2009-11-06 3:33 ` jason at gcc dot gnu dot org
2009-11-06 4:10 ` 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).