Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11260 > unrolled thread
| Started by | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| First post | 2011-11-04 11:52 -0700 |
| Last post | 2011-11-05 22:35 +0100 |
| Articles | 14 — 7 participants |
Back to article view | Back to comp.lang.c++
Odd error I can't seem to recreate Noah Roberts <roberts.noah@gmail.com> - 2011-11-04 11:52 -0700
Re: Odd error I can't seem to recreate Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-04 15:49 -0400
Re: Odd error I can't seem to recreate Noah Roberts <roberts.noah@gmail.com> - 2011-11-04 12:58 -0700
Re: Odd error I can't seem to recreate Richard Damon <news.x.richarddamon@xoxy.net> - 2011-11-04 16:15 -0400
Re: Odd error I can't seem to recreate "Gennaro Prota" <gennaro.prota@gmail.com> - 2011-11-04 21:03 +0100
Re: Odd error I can't seem to recreate Noah Roberts <roberts.noah@gmail.com> - 2011-11-04 13:07 -0700
Re: Odd error I can't seem to recreate Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-04 16:43 -0400
Re: Odd error I can't seem to recreate Noah Roberts <roberts.noah@gmail.com> - 2011-11-04 13:56 -0700
Re: Odd error I can't seem to recreate "Gennaro Prota" <name.surname@gmail.com> - 2011-11-04 22:16 +0100
Re: Odd error I can't seem to recreate "Gennaro Prota" <gennaro.prota@gmail.com> - 2011-11-04 21:16 +0100
Re: Odd error I can't seem to recreate Noah Roberts <roberts.noah@gmail.com> - 2011-11-04 13:15 -0700
Re: Odd error I can't seem to recreate Ian Collins <ian-news@hotmail.com> - 2011-11-05 12:00 +1300
Re: Odd error I can't seem to recreate "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-11-05 18:48 +0100
Re: Odd error I can't seem to recreate "Gennaro Prota" <name.surname@gmail.com> - 2011-11-05 22:35 +0100
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-11-04 11:52 -0700 |
| Subject | Odd error I can't seem to recreate |
| Message-ID | <bbe45080-3e8d-4e2f-aefc-7ac0906a6872@s7g2000yqa.googlegroups.com> |
In a significant code base I'm running into this problem:
This works:
test_service service;
std::string result = job->run_query(service);
This does not.:
std::string result = job->run_query(test_service());
the run_query function expects a const reference to test_service's
base class:
struct location_job
{
virtual ~location_job() {}
virtual std::string run_query(location_service const& service) const
= 0;
};
The error I get from g++4.1.2 is:
pipe_processor_test.cpp:142: error: no matching function for call to
âtest_service::test_service(test_service)â
../inc/test_service.h:27: note: candidates are:
test_service::test_service(bool)
../inc/test_service.h:7: note:
test_service::test_service(test_service&)
The bool constructor is made by me, but the non-const copy constructor
is the compiler's. Line 7 is the opening brace for the class.
I can't make any sense of this. Does anyone have ANY idea what might
be going on so I can try to narrow it down and create a minimal
example to get better help? The attempts I've made so far work
fine.
Under what conditions in which the first could work might the second
not when the parameter is const ref? I can't think of any.
Thanks for any help that can be provided. I know it's a reach.
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-11-04 15:49 -0400 |
| Message-ID | <j91fkd$7uo$1@dont-email.me> |
| In reply to | #11260 |
On 11/4/2011 2:52 PM, Noah Roberts wrote:
> In a significant code base I'm running into this problem:
>
> This works:
> test_service service;
> std::string result = job->run_query(service);
>
> This does not.:
> std::string result = job->run_query(test_service());
>
> the run_query function expects a const reference to test_service's
> base class:
>
> struct location_job
> {
> virtual ~location_job() {}
>
> virtual std::string run_query(location_service const& service) const
> = 0;
> };
Seems like there is some kind of relationship between 'location_service'
and 'test_service', but you decided to omit it. Perhaps you could
elaborate? Is 'test_service' derived from 'location_service' as private
or protected?
> The error I get from g++4.1.2 is:
>
> pipe_processor_test.cpp:142: error: no matching function for call to
> âtest_service::test_service(test_service)â
> ../inc/test_service.h:27: note: candidates are:
> test_service::test_service(bool)
> ../inc/test_service.h:7: note:
> test_service::test_service(test_service&)
Is there the default c-tor for 'test_service'? I presume there is.
So, 'test_service' copy constructor takes a non-const reference. To
initialize the argument to your 'run_query', a temporary of type
'location_service' has to be created (or has to be able to be created),
and I am guessing there is no conversion that the compiler can use.
When you supply a "real" object, not a temporary, the derived-to base
conversion is used, and all is well.
> The bool constructor is made by me, but the non-const copy constructor
> is the compiler's.
What??? Why would the compiler create a non-const copy c-tor? Or,
rather, what have you done to tell it to create that particular form of
the copy c-tor?
> Line 7 is the opening brace for the class.
>
> I can't make any sense of this. Does anyone have ANY idea what might
> be going on so I can try to narrow it down and create a minimal
> example to get better help? The attempts I've made so far work
> fine.
>
> Under what conditions in which the first could work might the second
> not when the parameter is const ref? I can't think of any.
>
> Thanks for any help that can be provided. I know it's a reach.
Please try to narrow it down by copying your classes into a separate
module and gradually removing all that is irrelevant, while still trying
to repeat the compiler behavior. Then post the remaining source, which
by that time should be no larger than this:
struct loc {
loc() {}
loc(loc&) {}
};
struct test : loc {
test(test& t) : loc(t) {}
test() : loc() {}
};
void foo(const loc&);
int main()
{
foo(test()); // and here you should get an error
test t;
foo(t);
}
I don't get the error with Comeau online for this program, but (a) I was
just guessing, and (b) that is a different compiler.
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-11-04 12:58 -0700 |
| Message-ID | <16a6d920-6666-496d-b3b2-5d7785a3204d@u28g2000yqb.googlegroups.com> |
| In reply to | #11262 |
On Nov 4, 12:49 pm, Victor Bazarov <v.baza...@comcast.invalid> wrote:
> On 11/4/2011 2:52 PM, Noah Roberts wrote:
> > The bool constructor is made by me, but the non-const copy constructor
> > is the compiler's.
>
> What??? Why would the compiler create a non-const copy c-tor? Or,
> rather, what have you done to tell it to create that particular form of
> the copy c-tor?
>
Yes, that bothers me a great deal as well, but for some reason g++
seems to be making non-const copy constructors by default. Here's the
class declarations:
struct location_service // needs to be at least mockable.
{
virtual ~location_service() {}
enum coord_format { DMS, DECIMAL };
enum location_tech { LEAST, MOST, CELL, AGPS };
typedef std::auto_ptr<service_response> response_t;
// pure virtual calls...
};
#include "location_service.h"
struct test_service : location_service
{
// overrides of inherited virtuals...
test_service();
test_service(bool sleeper);
~test_service();
private:
struct impl;
std::auto_ptr<impl> pimpl;
};
No declaration of copy constructor anywhere. It's not the first time
I've seen it and I'm assuming it's some sort of quirk/bug in g++
4.1.2.
Switches are:
g++ -g $(INCLUDES) $(LIBFLAGS) $(WIN32_DEF) -DTEST -Wall -Werror -
pedantic -Wno-long-long
include flags are just a bunch of -I args. For libs I do a couple odd
things:
-Wl,-Bstatic $(CPPUNIT_LIBS) $(LOG_LIBS) -Wl,-Bdynamic -lpthread
But not THAT odd...
So I don't know WTF g++ is doing that for.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <news.x.richarddamon@xoxy.net> |
|---|---|
| Date | 2011-11-04 16:15 -0400 |
| Message-ID | <j91h55$idp$1@dont-email.me> |
| In reply to | #11264 |
On 11/4/11 3:58 PM, Noah Roberts wrote:
> On Nov 4, 12:49 pm, Victor Bazarov<v.baza...@comcast.invalid> wrote:
>> On 11/4/2011 2:52 PM, Noah Roberts wrote:
>
>>> The bool constructor is made by me, but the non-const copy constructor
>>> is the compiler's.
>>
>> What??? Why would the compiler create a non-const copy c-tor? Or,
>> rather, what have you done to tell it to create that particular form of
>> the copy c-tor?
>>
>
> Yes, that bothers me a great deal as well, but for some reason g++
> seems to be making non-const copy constructors by default. Here's the
> class declarations:
>
...
> struct test_service : location_service
> {
>
> // overrides of inherited virtuals...
>
> test_service();
> test_service(bool sleeper);
> ~test_service();
> private:
> struct impl;
> std::auto_ptr<impl> pimpl;
> };
>
> No declaration of copy constructor anywhere. It's not the first time
> I've seen it and I'm assuming it's some sort of quirk/bug in g++
> 4.1.2.
>
Note that auto_ptr has a non-const copy constructor, as copying an
auto_ptr changes the source auto pointer. Therefore any class that has
an auto_ptr member will by default have a non-const copy constructor, as
it can't make a const copy constructor.
[toc] | [prev] | [next] | [standalone]
| From | "Gennaro Prota" <gennaro.prota@gmail.com> |
|---|---|
| Date | 2011-11-04 21:03 +0100 |
| Message-ID | <op.v4ft0tyaon14i0@gp.homenet.telecomitalia.it> |
| In reply to | #11260 |
On Fri, 04 Nov 2011 19:52:56 +0100, Noah Roberts <roberts.noah@gmail.com>
wrote:
> In a significant code base I'm running into this problem:
>
> This works:
> test_service service;
> std::string result = job->run_query(service);
>
> This does not.:
> std::string result = job->run_query(test_service());
>
> the run_query function expects a const reference to test_service's
> base class:
>
> struct location_job
> {
> virtual ~location_job() {}
>
> virtual std::string run_query(location_service const& service) const
> = 0;
> };
>
> The error I get from g++4.1.2 is:
>
> pipe_processor_test.cpp:142: error: no matching function for call to
> âtest_service::test_service(test_service)â
> ../inc/test_service.h:27: note: candidates are:
> test_service::test_service(bool)
> ../inc/test_service.h:7: note:
> test_service::test_service(test_service&)
>
> The bool constructor is made by me, but the non-const copy constructor
> is the compiler's. Line 7 is the opening brace for the class.
>
> I can't make any sense of this. Does anyone have ANY idea what might
> be going on so I can try to narrow it down and create a minimal
> example to get better help? The attempts I've made so far work
> fine.
>
> Under what conditions in which the first could work might the second
> not when the parameter is const ref? I can't think of any.
>
> Thanks for any help that can be provided. I know it's a reach.
Try looking at the copy constructors of test_service's members:
- the direct and virtual base classes
- the non-static data members
At least one of them should have a copy constructor without
const-qualification on the first parameter, which is why the
compiler-generated copy constructor of test_service lacks it as
well.
--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
[toc] | [prev] | [next] | [standalone]
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-11-04 13:07 -0700 |
| Message-ID | <185163d7-5063-4ed1-958d-592b377b3b31@k10g2000yqn.googlegroups.com> |
| In reply to | #11263 |
On Nov 4, 1:03 pm, "Gennaro Prota" <gennaro.pr...@gmail.com> wrote:
> On Fri, 04 Nov 2011 19:52:56 +0100, Noah Roberts <roberts.n...@gmail.com>
> wrote:
>
>
>
>
>
>
>
>
>
> > In a significant code base I'm running into this problem:
>
> > This works:
> > test_service service;
> > std::string result = job->run_query(service);
>
> > This does not.:
> > std::string result = job->run_query(test_service());
>
> > the run_query function expects a const reference to test_service's
> > base class:
>
> > struct location_job
> > {
> > virtual ~location_job() {}
>
> > virtual std::string run_query(location_service const& service) const
> > = 0;
> > };
>
> > The error I get from g++4.1.2 is:
>
> > pipe_processor_test.cpp:142: error: no matching function for call to
> > âtest_service::test_service(test_service)â
> > ../inc/test_service.h:27: note: candidates are:
> > test_service::test_service(bool)
> > ../inc/test_service.h:7: note:
> > test_service::test_service(test_service&)
>
> > The bool constructor is made by me, but the non-const copy constructor
> > is the compiler's. Line 7 is the opening brace for the class.
>
> > I can't make any sense of this. Does anyone have ANY idea what might
> > be going on so I can try to narrow it down and create a minimal
> > example to get better help? The attempts I've made so far work
> > fine.
>
> > Under what conditions in which the first could work might the second
> > not when the parameter is const ref? I can't think of any.
>
> > Thanks for any help that can be provided. I know it's a reach.
>
> Try looking at the copy constructors of test_service's members:
>
> - the direct and virtual base classes
> - the non-static data members
>
> At least one of them should have a copy constructor without
> const-qualification on the first parameter, which is why the
> compiler-generated copy constructor of test_service lacks it as
> well.
Thanks. This does appear to be the main issue. There is an auto_ptr
in the test_service.
I recreated the problem:
cat wtf.cpp
#include <memory>
struct base
{
virtual ~base() {}
};
struct derived : base
{
std::auto_ptr<int> i;
derived() : i() {}
//private:
//derived(derived const&);
};
struct base;
struct base2
{
virtual ~base2() {}
virtual void fun(base const&) const = 0;
};
struct derived2 : base2
{
void fun(base const&) const {}
};
struct base3
{
virtual ~base3() {}
virtual std::auto_ptr<base2> get() const = 0;
};
struct derived3 : base3
{
std::auto_ptr<base2> get() const { return
std::auto_ptr<base2>(new derived2); }
};
int main()
{
derived3 d3;
std::auto_ptr<base2> b2 = d3.get();
b2->fun(derived());
}
Now I get all the errors I don't expect that are giving me crap in the
original code:
g++ wtf.cpp
wtf.cpp: In function âint main()â:
wtf.cpp:42: error: no matching function for call to
âderived::derived(derived)â
wtf.cpp:9: note: candidates are: derived::derived(derived&)
Victor said:
So, 'test_service' copy constructor takes a non-const reference. To
initialize the argument to your 'run_query', a temporary of type
'location_service' has to be created (or has to be able to be
created),
and I am guessing there is no conversion that the compiler can use.
.................
As I understood it, because it takes a non-const reference the
temporary created by the "test_service()" call should be directly
used, rather than a copy of it attempted. Why is it necessary to make
a temporary of 'location_service', or 'base' in the above code?
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-11-04 16:43 -0400 |
| Message-ID | <j91iqa$urv$1@dont-email.me> |
| In reply to | #11265 |
On 11/4/2011 4:07 PM, Noah Roberts wrote:
> [.. seems that auto_ptr is to blame ..]
> I recreated the problem:
>
> cat wtf.cpp
> #include<memory>
>
> struct base
> {
> virtual ~base() {}
> };
>
> struct derived : base
> {
> std::auto_ptr<int> i;
> derived() : i() {}
> //private:
> //derived(derived const&);
> };
>
> struct base;
> struct base2
> {
> virtual ~base2() {}
> virtual void fun(base const&) const = 0;
> };
> struct derived2 : base2
> {
> void fun(base const&) const {}
> };
>
> struct base3
> {
> virtual ~base3() {}
> virtual std::auto_ptr<base2> get() const = 0;
> };
> struct derived3 : base3
> {
> std::auto_ptr<base2> get() const { return
> std::auto_ptr<base2>(new derived2); }
> };
>
> int main()
> {
> derived3 d3;
> std::auto_ptr<base2> b2 = d3.get();
> b2->fun(derived());
> }
Comeau online compiles it without even a blink. So does VC++ 2010 on my
machine.
> Now I get all the errors I don't expect that are giving me crap in the
> original code:
>
> g++ wtf.cpp
> wtf.cpp: In function âint main()â:
> wtf.cpp:42: error: no matching function for call to
> âderived::derived(derived)â
> wtf.cpp:9: note: candidates are: derived::derived(derived&)
>
> Victor said:
> So, 'test_service' copy constructor takes a non-const reference. To
> initialize the argument to your 'run_query', a temporary of type
> 'location_service' has to be created (or has to be able to be
> created),
> and I am guessing there is no conversion that the compiler can use.
> .................
>
> As I understood it, because it takes a non-const reference the
> temporary created by the "test_service()" call should be directly
> used, rather than a copy of it attempted. Why is it necessary to make
> a temporary of 'location_service', or 'base' in the above code?
I may just as well be wrong here.
So far I failed to reproduce your issue with another compiler. I don't
have access to gcc/g++ at this time.
Let's drop the auto_ptr member and try declaring our own copy-c-tor that
takes a non-const ref...
I've dropped the 'i' member from 'derived' and instead added a copy
c-tor with a non-const ref argument, both Comeau online and VC++ still
compiled it.
Something is funky with g++, I am guessing. Can it compile this:
struct base
{
virtual ~base() {}
};
struct derived : base
{
derived() : base() {}
derived(derived& d) : base(d) {}
};
void fun(base const& b) { return; }
int main()
{
derived d;
fun(d);
fun(derived());
}
?
V
--
I do not respond to top-posted replies, please don't ask
[toc] | [prev] | [next] | [standalone]
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-11-04 13:56 -0700 |
| Message-ID | <c2393012-c7bb-4517-a717-0f8225e52d20@eh5g2000vbb.googlegroups.com> |
| In reply to | #11268 |
On Nov 4, 1:43 pm, Victor Bazarov <v.baza...@comcast.invalid> wrote:
> Something is funky with g++, I am guessing. Can it compile this:
>
> struct base
> {
> virtual ~base() {}
> };
>
> struct derived : base
> {
> derived() : base() {}
> derived(derived& d) : base(d) {}
> };
>
> void fun(base const& b) { return; }
>
> int main()
> {
> derived d;
> fun(d);
> fun(derived());
> }
Nope. It complains about the second fun call. No matching function
for call to derived::derived(derived).
[toc] | [prev] | [next] | [standalone]
| From | "Gennaro Prota" <name.surname@gmail.com> |
|---|---|
| Date | 2011-11-04 22:16 +0100 |
| Message-ID | <op.v4fxddyyb6xo2g@gp.homenet.telecomitalia.it> |
| In reply to | #11269 |
On Fri, 04 Nov 2011 21:56:29 +0100, Noah Roberts <roberts.noah@gmail.com>
wrote:
> On Nov 4, 1:43 pm, Victor Bazarov <v.baza...@comcast.invalid> wrote:
>
>> Something is funky with g++, I am guessing. Can it compile this:
>>
>> struct base
>> {
>> virtual ~base() {}
>> };
>>
>> struct derived : base
>> {
>> derived() : base() {}
>> derived(derived& d) : base(d) {}
>> };
>>
>> void fun(base const& b) { return; }
>>
>> int main()
>> {
>> derived d;
>> fun(d);
>> fun(derived());
>> }
>
> Nope. It complains about the second fun call. No matching function
> for call to derived::derived(derived).
That's correct in C++03. The restriction has been lifted in C++11.
--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
[toc] | [prev] | [next] | [standalone]
| From | "Gennaro Prota" <gennaro.prota@gmail.com> |
|---|---|
| Date | 2011-11-04 21:16 +0100 |
| Message-ID | <op.v4fumaxton14i0@gp.homenet.telecomitalia.it> |
| In reply to | #11263 |
On Fri, 04 Nov 2011 21:03:55 +0100, Gennaro Prota
<gennaro.prota@gmail.com> wrote:
> Try looking at the copy constructors of test_service's members:
>
> - the direct and virtual base classes
> - the non-static data members
>
> At least one of them should have a copy constructor without
> const-qualification on the first parameter, which is why the
> compiler-generated copy constructor of test_service lacks it as
> well.
Poorly worded, sorry (although it shouldn't affect
understandability). Should have been:
Try looking at the copy constructors of test_service's:
- direct and virtual base classes
- non-static data member types (their elements in case of
arrays)
--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
[toc] | [prev] | [next] | [standalone]
| From | Noah Roberts <roberts.noah@gmail.com> |
|---|---|
| Date | 2011-11-04 13:15 -0700 |
| Message-ID | <e65d1df3-c094-463b-b46d-3d20e1000cbd@o5g2000yqa.googlegroups.com> |
| In reply to | #11260 |
On Nov 4, 11:52 am, Noah Roberts <roberts.n...@gmail.com> wrote:
> Under what conditions in which the first could work might the second
> not when the parameter is const ref? I can't think of any.
Here's a further revision of the problem code:
cat wtf.cpp
#include <memory>
#include <iostream>
struct base
{
virtual ~base() {}
virtual void f() const = 0;
};
struct derived : base
{
#ifdef HUH
private:
derived(derived const&);
#endif
public:
derived() {}
void f() const { std::cout << "derived::f() \n"; }
};
struct base;
struct base2
{
virtual ~base2() {}
virtual void fun(base const&) const = 0;
};
struct derived2 : base2
{
void fun(base const& b) const { b.f(); }
};
struct base3
{
virtual ~base3() {}
virtual std::auto_ptr<base2> get() const = 0;
};
struct derived3 : base3
{
std::auto_ptr<base2> get() const { return
std::auto_ptr<base2>(new derived2); }
};
int main()
{
derived3 d3;
std::auto_ptr<base2> b2 = d3.get();
b2->fun(derived());
}
The result of compilation and run without -DHUH:
$ g++ wtf.cpp
$ ./a.out
derived::f()
The result with -DHUH:
$ g++ -DHUH wtf.cpp
wtf.cpp: In function âint main()â:
wtf.cpp:14: error: âderived::derived(const derived&)â is private
wtf.cpp:47: error: within this context
So it appears that the problem is with the temporary being created,
and that I don't understand. As far as I knew, const reference
allowed you to use the initially created temporary directly. Where's
the standard text that explains why it's doing this?
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2011-11-05 12:00 +1300 |
| Message-ID | <9hj94bF62fU6@mid.individual.net> |
| In reply to | #11271 |
On 11/ 5/11 09:15 AM, Noah Roberts wrote: > On Nov 4, 11:52 am, Noah Roberts<roberts.n...@gmail.com> wrote: > >> Under what conditions in which the first could work might the second >> not when the parameter is const ref? I can't think of any. > > Here's a further revision of the problem code: > <snip> > > The result of compilation and run without -DHUH: > > $ g++ wtf.cpp > $ ./a.out > derived::f() > > The result with -DHUH: > $ g++ -DHUH wtf.cpp > wtf.cpp: In function âint main()â: > wtf.cpp:14: error: âderived::derived(const derived&)â is private > wtf.cpp:47: error: within this context > > So it appears that the problem is with the temporary being created, > and that I don't understand. As far as I knew, const reference > allowed you to use the initially created temporary directly. Where's > the standard text that explains why it's doing this? Compiler bug? It compiles fine with gcc 4.5.1. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2011-11-05 18:48 +0100 |
| Message-ID | <j93st2$g18$1@dont-email.me> |
| In reply to | #11260 |
On 04.11.2011 19:52, Noah Roberts wrote:
> In a significant code base I'm running into this problem:
>
> This works:
> test_service service;
> std::string result = job->run_query(service);
> This does not.:
> std::string result = job->run_query(test_service());
At this point the service object has been destroyed.
And perhaps the query is running in the background?
Oh, I see below that the problem isn't the obvious asynchronous one that
I thought it was.
Or perhaps the potential problem I mentioned above comes in addition.
OK then, on to the real problem...
> the run_query function expects a const reference to test_service's
> base class:
>
> struct location_job
> {
> virtual ~location_job() {}
>
> virtual std::string run_query(location_service const& service) const
> = 0;
> };
>
> The error I get from g++4.1.2 is:
>
> pipe_processor_test.cpp:142: error: no matching function for call to
> âtest_service::test_service(test_service)â
> ../inc/test_service.h:27: note: candidates are:
> test_service::test_service(bool)
> ../inc/test_service.h:7: note:
> test_service::test_service(test_service&)
Well, first note that the formal argument is of type `location_service
const&`, while the actual argument is of type `test_service`.
Assumming that `test_service` is derived from `location_service`, or is
the same class.
Then apparently g++ abides by C++98 rules that require an accessible
copy constructor, because C++98 allowed the compiler to introduce any
number of temporaries. This was fixed in C++03. But with C++98 rules, a
copy constructor must be accessible and the result is "as if" it's used,
when you pass a temporary to T const&.
And the test_service copy constructor has non-const formal argument,
test_service&
Hence it cannot be used for copying the actual argument.
> The bool constructor is made by me, but the non-const copy constructor
> is the compiler's. Line 7 is the opening brace for the class.
It may have been generated due to presence of e.g. std::auto_ptr as member.
Any data member or base class that has T(T&) forces that.
It couldn't (logically) be any other way.
> I can't make any sense of this. Does anyone have ANY idea what might
> be going on so I can try to narrow it down and create a minimal
> example to get better help? The attempts I've made so far work
> fine.
Yes, see above.
> Under what conditions in which the first could work might the second
> not when the parameter is const ref? I can't think of any.
>
> Thanks for any help that can be provided. I know it's a reach.
Cheers & hth.,
- Alf
[toc] | [prev] | [next] | [standalone]
| From | "Gennaro Prota" <name.surname@gmail.com> |
|---|---|
| Date | 2011-11-05 22:35 +0100 |
| Message-ID | <op.v4hswoeab6xo2g@gp.homenet.telecomitalia.it> |
| In reply to | #11276 |
On Sat, 05 Nov 2011 18:48:15 +0100, Alf P. Steinbach
<alf.p.steinbach+usenet@gmail.com> wrote:
> Then apparently g++ abides by C++98 rules that require an accessible
> copy constructor, because C++98 allowed the compiler to introduce any
> number of temporaries. This was fixed in C++03.
I don't have the standard handy but I'm pretty sure that this
was changed *after* C++03 (I think it all began with core issue
391).
--
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web