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


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

Re: Strange gcc compiler error?

From Kai-Uwe Bux <jkherciueh@gmx.net>
Newsgroups comp.lang.c++
Subject Re: Strange gcc compiler error?
Followup-To comp.lang.c++
Date 2011-05-03 19:31 +0200
Organization University of Bielefeld
Message-ID <ippe4t$678$1@hoshi.visyn.net> (permalink)
References <47dc9f45-a4a5-4b61-aaf2-92c1602cc1cf@i39g2000prd.googlegroups.com>

Followups directed to: comp.lang.c++

Show all headers | View raw


J Cook wrote:

> Can anyone explain this error?  It seems as if the compiler is using
> the name of the first parameter as the temporary object name?
> 
> class Foo
> {
>   Foo(int s) {}
> 
> };
> 
> void foo()
> {
>  int test = 4;
>  Foo(test);  // create a temporary. Thinks it is named "test" ??
> }
> 
> int main()
> {
>   foo();
> }
> 
> # In function 'void foo()'
> # error: conflicting declaration 'Foo test'
> # 'test' has a previous declaration as 'int test'
[...]

The compiler treats the marked line not as creating a temporary but as a 
variable declaration of the variable test. At least, that is what the error 
message says.

What one would expect, is a message: "constructor Foo(int) is private and 
cannot be used in this context.". However, after discarding the private 
constructor, the compiler goes on and tries the default constructor. That's 
why you get a redefinition error message. The compiler does this, because 
clause [8.3/6] says that one way of reading

  Foo(test);

is:

  Foo test;


Best,

Kai-Uwe Bux

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


Thread

Strange gcc compiler error? J Cook <joecook@gmail.com> - 2011-05-03 09:51 -0700
  Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:01 -0400
    Re: Strange gcc compiler error? J Cook <joecook@gmail.com> - 2011-05-03 10:06 -0700
      Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:09 -0400
        Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:10 -0400
          Re: Strange gcc compiler error? Öö Tiib <ootiib@hot.ee> - 2011-05-03 10:36 -0700
            Re: Strange gcc compiler error? James Kanze <james.kanze@gmail.com> - 2011-05-03 15:02 -0700
  Re: Strange gcc compiler error? Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-05-03 19:31 +0200

csiph-web