473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

gcc at fault?

Hi all,

This code failed to compile (using GCC 4.1). Other compilers did not
complain.

template <class T>
struct Base
{
Base( T& ){}
};

struct Derived : Base<Derived>
{
Derived()
: Base( *this ) <<---Error here!
{}
};

GCC failed with error:

error: no matching function for call to
`appCFDC::Base<appCFDC::Derived>::Base()'

The problem is fixed by qualifying the Base type explicitly:
: Base<Derived>( *this )...

Is GCC at fault here? Anybody willing to sight the standard?

Kind regards,

Werner

Aug 31 '07 #1
4 1163
werasm wrote:
This code failed to compile (using GCC 4.1). Other compilers did not
complain.

template <class T>
struct Base
{
Base( T& ){}
};

struct Derived : Base<Derived>
{
Derived()
: Base( *this ) <<---Error here!
{}
};

GCC failed with error:

error: no matching function for call to
`appCFDC::Base<appCFDC::Derived>::Base()'

The problem is fixed by qualifying the Base type explicitly:
>Base<Derived>( *this )...

Is GCC at fault here? Anybody willing to sight the standard?
Too little sleep last night to be able to dig through the Standard,
but GCC's behaviour does look justified. 'Base' is a template-id,
not a type-id. To make it a type-id (which is what should be found
when looking up the base class name), one needs the template
argument list (including the angle brackets)...

I am sure somebody will find that (or a rebuttal to that) in the
Standard.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 31 '07 #2
Victor Bazarov wrote:
Too little sleep last night to be able to dig through the Standard,
but GCC's behaviour does look justified.
Yes, I have the same problem. Too little time to delve into
the standard (need to keep that balance...). I also know there
are guys here that know the standard by heart (almost) and
probably know the answer, hence the question. I also prefer
writing code that is compliant (else I run into trouble with code
that fails to compile somewhere down the line).

Explicitly qualifying Base will never be wrong, therefore it is
probably the way to go (if the other way cannot be proven right,
at least). Was just curious.

Regards and Thanks,

Werner

Aug 31 '07 #3
werasm <we****@gmail.comwrote in news:1188571730.473230.203540
@r34g2000hsd.googlegroups.com:
Victor Bazarov wrote:
>Too little sleep last night to be able to dig through the Standard,
but GCC's behaviour does look justified.

Yes, I have the same problem. Too little time to delve into
the standard (need to keep that balance...). I also know there
are guys here that know the standard by heart (almost) and
probably know the answer, hence the question. I also prefer
writing code that is compliant (else I run into trouble with code
that fails to compile somewhere down the line).

Explicitly qualifying Base will never be wrong, therefore it is
probably the way to go (if the other way cannot be proven right,
at least). Was just curious.

Regards and Thanks,

Werner

Well, *I* know that VC doesn't use correct two phase lookup and
therefore finds names it technically shouldn't. I have never had a case
where this caused actual problems though, but technically it's wrong.

If I had to guess, I would guess gcc is right as well. My reasoning
(and it may well be faulty) goes like this. What is needed to invoke
the base class constructor is a class name. Template classes can't
deduce their template argument types, therefore you need to provide it.
Same rule holds here, Base would have to somehow deduce its template
argument and that doesn't normally work.

As you can see though, I have no rules to quote and my quick attempt at
finding them proved that I am not proficient in standard-ness.

joe
Aug 31 '07 #4
On Fri, 31 Aug 2007 06:00:24 -0700, werasm wrote:
Hi all,

This code failed to compile (using GCC 4.1). Other compilers did not
complain.

template <class T>
struct Base
{
Base( T& ){}
};

struct Derived : Base<Derived>
{
Derived()
: Base( *this ) <<---Error here!
{}
};

GCC failed with error:

error: no matching function for call to
`appCFDC::Base<appCFDC::Derived>::Base()'

The problem is fixed by qualifying the Base type explicitly: :
Base<Derived>( *this )...

Is GCC at fault here? Anybody willing to sight the standard?
GCC is correct. By 12.6.2/2 in the above case the name of a class needs
to be given. The name of a class according to 9/1 is either the name of a
non-template class/struct/union or a template-id. Here it obviously needs
to be a template-id which includes the template argument list in <>
brackets according to 14.2/1.

The above code is therefore indeed ill-formed. Compilers not outputting a
diagnostic for the above code do not conform to the standard (which of
course most compilers do not anyway for various reasons).

--
Markus Schoder
Aug 31 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zheng Da | last post by:
Program received signal SIGSEGV, Segmentation fault. 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x40093343 in _int_malloc () from /lib/tls/libc.so.6 #1 0x40094c54 in malloc...
5
by: Fra-it | last post by:
Hi everybody, I'm trying to make the following code running properly, but I can't get rid of the "SEGMENTATION FAULT" error message when executing. Reading some messages posted earlier, I...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
3
by: Moshe Kravchik | last post by:
Hi! We have a Web Service written in ATL Server and a client written in Java using Axis. When something goes wrong on the server side, it returns an HRESULT of the error which is translated into...
0
by: relaxedrob | last post by:
Hi All, I have a portType such as this: <portType name="CMLeJobSoapGetEmpBrand"> <operation name="EJobGetEmpBrand"> <input message="tns:EJobEmpBrdReq" name="EJobEmpBrdReq"/> <output...
27
by: Paminu | last post by:
I have a wierd problem. In my main function I print "test" as the first thing. But if I run the call to node_alloc AFTER the printf call I get a segmentation fault and test is not printed! ...
7
by: pycraze | last post by:
I would like to ask a question. How do one handle the exception due to Segmentation fault due to Python ? Our bit operations and arithmetic manipulations are written in C and to some of our...
3
by: madunix | last post by:
My Server is suffering bad lag (High Utlization) I am running on that server Oracle10g with apache_1.3.35/ php-4.4.2 Web visitors retrieve data from the web by php calls through oci cobnnection...
0
by: Equinex | last post by:
Hi, I am trying to call a Web Service using Php and Soap. Why does the following Php 5 code return? try { //$ExchangeLoginResult = $ExchangeClient->Login(array("request" =>
3
by: =?Utf-8?B?TWFucHJlZXQgU3VzaGls?= | last post by:
I am having a Webservice within which i am throwing SOAP Exceptions and therefore whenever something wrong happens a SOAP fault comes up in the response - see below: <?xml version="1.0"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.