Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11276

Re: Odd error I can't seem to recreate

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Odd error I can't seem to recreate
Date 2011-11-05 18:48 +0100
Organization A noiseless patient Spider
Message-ID <j93st2$g18$1@dont-email.me> (permalink)
References <bbe45080-3e8d-4e2f-aefc-7ac0906a6872@s7g2000yqa.googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web