Please consider this code:
void foo(int);
template<typena me T>
struct S
{
void f()
{
foo(1); // (1)
T t;
foo(t); // (2)
}
};
void foo(int*);
// <--- point of instantiation
int main()
{
S<int*> a;
a.f();
}
In (1), foo is not a dependent name, so point of definition binding applies
and void foo(int) is called. But what about (2)? I think foo IS a dependent
name there and point of instantiation binding applies. At that point,
void foo(int*) is in scope, which means the code has no problem.
But Comeau rejects the code. Is it correct or not?
--
ES Kim 4 1676
ES Kim wrote: Please consider this code:
void foo(int);
template<typena me T> struct S { void f() { foo(1); // (1) T t; foo(t); // (2) } };
void foo(int*);
// <--- point of instantiation int main() { S<int*> a; a.f(); }
In (1), foo is not a dependent name, so point of definition binding applies and void foo(int) is called. But what about (2)? I think foo IS a dependent name there
You made me look up the rules for dependent names, and, yes, you're
correct here, 'foo' is a dependent name.
and point of instantiation binding applies. At that point, void foo(int*) is in scope, which means the code has no problem. But Comeau rejects the code. Is it correct or not?
Seems to be a bug. Have you tried contacting Comeau?
FWIW, Visual C++ 2003 gets it right. g++ v2.95.2 gets it right. g++
v3.2.2 gets it right. MIPSpro v7.4 gets it right. HP's aCC v3.50 gets
it right... I decided to stop at that point.
V
ES Kim wrote in news:d3******** **@news1.kornet .net in comp.lang.c++: Please consider this code:
void foo(int);
template<typena me T> struct S { void f() { foo(1); // (1) T t; foo(t); // (2) } };
void foo(int*);
// <--- point of instantiation int main() { S<int*> a; a.f(); }
In (1), foo is not a dependent name, so point of definition binding applies and void foo(int) is called. But what about (2)?
(2) is a dependant name, it depends on T a template paramiter, it can be
nothing else.
I think foo IS a dependent name there and point of instantiation binding applies.
foo( t ) (2) can only be bound to function's that were declared prior
to the defenition (body) of S<>:f(), only function's found by ADL
(Argument dependent Lookup) are allowed to bypass this rule.
In this case its foo( int ) as that is the *only* foo available when
S<>::f() is parsed.
At that point, void foo(int*) is in scope,
foo(int *) is an overload of foo(int) however it isn't found by ADL
as ADL isn't used when all paramiters are pure inbult types (int,
int * etc).
For ADL to be used T would need to be declared in a different namespace
to S<>, in which case the compiler would use ADL to look for overloads
foo( convertible_fro m_T ) in T's namespace, whether or not they were
declared before the defenition of s<>::f().
which means the code has no problem. But Comeau rejects the code. Is it correct or not?
Its correct an int * can't be converted to an int without a cast.
Rob.
-- http://www.victim-prime.dsl.pipex.com/
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:om******** ***********@new sread1.mlpsca01 .us.to.verio.ne t... ES Kim wrote: > and point of instantiation binding applies. At that point, void foo(int*) is in scope, which means the code has no problem. But Comeau rejects the code. Is it correct or not? Seems to be a bug. Have you tried contacting Comeau?
Here you and Rob go separate ways.
Rob's answer looks more convincing, though. FWIW, Visual C++ 2003 gets it right. g++ v2.95.2 gets it right. g++ v3.2.2 gets it right. MIPSpro v7.4 gets it right. HP's aCC v3.50 gets it right... I decided to stop at that point.
Whoa.. You have quite many machines in your reach.
Thank you for the information.
--
ES Kim
"Rob Williscroft" <rt*@freenet.co .uk> wrote in message
news:Xn******** *************** ***********@216 .196.109.145... ES Kim wrote in news:d3******** **@news1.kornet .net in comp.lang.c++: I think foo IS a dependent name there and point of instantiation binding applies.
foo( t ) (2) can only be bound to function's that were declared prior to the defenition (body) of S<>:f(), only function's found by ADL (Argument dependent Lookup) are allowed to bypass this rule.
In this case its foo( int ) as that is the *only* foo available when S<>::f() is parsed.
At that point, void foo(int*) is in scope,
foo(int *) is an overload of foo(int) however it isn't found by ADL as ADL isn't used when all paramiters are pure inbult types (int, int * etc).
For ADL to be used T would need to be declared in a different namespace to S<>, in which case the compiler would use ADL to look for overloads foo( convertible_fro m_T ) in T's namespace, whether or not they were declared before the defenition of s<>::f().
which means the code has no problem. But Comeau rejects the code. Is it correct or not?
Its correct an int * can't be converted to an int without a cast.
Yes, now it makes sense. Some guy tried a slightly tweaked version.
void foo(int);
template<typena me T>
struct S
{
void f()
{
foo(1); // (1)
T t;
foo(t); // (2)
}
};
class C {}; // modified
void foo(C); // modified
// <--- point of instantiation
int main()
{
S<C> a; // modified
a.f();
}
Now Comeau compiles clean, since 'C' is a user-defined name and ADL mechanism
works according to your explanation.
I remember I was helped with ADL from you months ago. Thank you again.
--
ES Kim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: zhou |
last post by:
Hi there,
We have a compiler specific issue which requires us to force template instantiation. This works fine. The problem comes
when I try using std:find() on vector. Since vector has no member function find() and I have to use std::find(). The
linker fails on unsatisified symbols in find().
I think this is because find() is a template function and I have to force instantiation. However, I donot know the
correct syntax of doing so....
|
by: Karthik D |
last post by:
Hello All,
I am a newbie to C++ code particularly templates.Below is a
template class defintion and I couldn't find the ObjPtr/ObjFnPtr class
definition anywhere in source code.
template<class ObjPtr, class ObjFunPtr>
class MemberFunctor0 : public Functor
{
public:
MemberFunctor0(const ObjPtr& obj, const ObjFunPtr& objfn)
: _obj(obj), _objfn(objfn)
|
by: C. Carbonera |
last post by:
/*
Hi,
I have a problem with explicit instantiation of templates in Visual
C++ 6.0.
I have provided the source below. I have an example of a function
template that produces incorrect output in the code below.
The function
template < typename T >
|
by: David |
last post by:
Assuming of course that the instantiation statement is 100% ok.
As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
(and Borland) but since I was suspicious that it was OK there "more by luck
than brain", I checked the same on Linux\GNU were the instantiation failed.
This question is more for people who know well the C++ ISO standard, the
chapter on templates. My hunch is that the problem is with the language spec....
|
by: carlos.urena.almagro |
last post by:
Hello,
I'm sorry if this post raises a question with obvious answer, or if it
has been already posted and solved. I was wondering about how the
compiler (in my case, gcc 4.0.2 on linux) handles templates
instantation, and what the standard says about that. I created a
"difficult" case, in which the meaning of a call to a function (which
is dependant) depends on the context where a template is instantiated.
I have three compilation...
| |
by: erictham115 |
last post by:
Error C2555
c:\C++ projects\stat1\stdmatrix_adapt.h(41) : error C2555:
'std_tools::Matrix_adapter<T>::at': overriding virtual function return
type differs and is not covariant from 'ple::imtx_impl<T>::at'
//in my program: the derived class
template <class T>
class Matrix_adapter : public ple::imtx_impl<T{
protected:
|
by: SpreadTooThin |
last post by:
I am having trouble getting a piece of code to compile on VC++ 6.0...
Compiles fine on MAC OS X under X-Code....
#include <list>
class myClass
{
private:
std::string name;
std::list<myClassobjects;
|
by: yuanhp_china |
last post by:
I define a class in A.h:
template <class Tclass A{
public:
void get_elem( const T&) ;
};
|
by: greek_bill |
last post by:
Hi,
I have a template function for which I use SFINAE to restrict one of
the parameters. Then I also have a partial specialization of this
function.I would like to provide an explicit instantiation of the
partially specialized version, but my compiler (VC8) complains because
it fails the SFINAE version.
I just realized as I was typing this that I'm using partial
_function_ specialization. I'm sure I remember reading somewhere that
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |