Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > bug in gcc?

Reply
Thread Tools

bug in gcc?

 
 
Timon Gehr
Guest
Posts: n/a
 
      12-23-2011
g++ fails to compile the following code snippet:
---
struct B{int foo;};

template<class T> int foo(T x){
int y = x.foo<1>(0);
return y;
}

int main(){
int c = foo(B());
}
---
---
bug.cpp: In function ‘int foo(T) [with T = B]’:
bug.cpp:10:17: instantiated from here
bug.cpp:5:20: error: ‘foo’ is not a member template function
---

The code compiles if the template function is renamed from 'foo' to
'bar'.

Is this a bug?


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      12-23-2011
On 23.12.2011 12:04, Timon Gehr wrote:
> g++ fails to compile the following code snippet:
> ---
> struct B{int foo;};
>
> template<class T> int foo(T x){
> int y = x.foo<1>(0);
> return y;
> }
>
> int main(){
> int c = foo(B());
> }
> ---
> ---
> bug.cpp: In function ‘int foo(T) [with T = B]’:
> bug.cpp:10:17: instantiated from here
> bug.cpp:5:20: error: ‘foo’ is not a member template function
> ---
>
> The code compiles if the template function is renamed from 'foo' to
> 'bar'.
>
> Is this a bug?


If it's true that it compiles with the simple renaming, then yes.

However, your posting is rather unclear.

Why on Earth are you showing the non-problematic code instead of the
code where there is possibly a problem?

Given the lack of logic in the posting, I think it's more likely that
you're confused about this.

I.e., a PEBKAC problem.


Cheers & hth.,

- Alf
 
Reply With Quote
 
 
 
 
Timon Gehr
Guest
Posts: n/a
 
      12-23-2011
On Dec 23, 12:28*pm, "Alf P. Steinbach" <alf.p.steinbach
(E-Mail Removed)> wrote:
> On 23.12.2011 12:04, Timon Gehr wrote:
>
>
>
>
>
>
>
>
>
> > g++ fails to compile the following code snippet:
> > ---
> > struct B{int foo;};

>
> > template<class T> *int foo(T x){
> > * * *int y = x.foo<1>(0);
> > * * *return y;
> > }

>
> > int main(){
> > * * *int c = foo(B());
> > }
> > ---
> > ---
> > bug.cpp: In function ‘int foo(T) [with T = B]’:
> > bug.cpp:10:17: * instantiated from here
> > bug.cpp:5:20: error: ‘foo’ is not a member template function
> > ---

>
> > The code compiles if the template function is renamed from 'foo' to
> > 'bar'.

>
> > Is this a bug?

>
> If it's true that it compiles with the simple renaming, then yes.
>
> However, your posting is rather unclear.


I disagree.

>
> Why on Earth are you showing the non-problematic code instead of the
> code where there is possibly a problem?
>


I am showing the problematic code. I think it is valid C++. GCC
rejects it. The code where 'foo' is replaced by 'bar' is not
problematic: It is valid C++ and GCC compiles it.

> Given the lack of logic in the posting, I think it's more likely that
> you're confused about this.


I don't know, but I think it is possible that you are confused because
x.foo<1>(0) looks like a template function instantiation. I thought
that was the compiler's issue too, but I was wrong: I have managed to
reduce the code to a handy one-liner that does not contain it.

---
template<class T> bool foo(T x){return x.foo<1;}
---
---
bug.cpp: In function ‘bool foo(T)’:
bug.cpp:1:42: error: parse error in template argument list
---

Again, renaming the template function makes the code compile.

>
> I.e., a PEBKAC problem.
>
> Cheers & hth.,
>
> - Alf


Thank you.
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      12-23-2011
Alf P. Steinbach wrote:

> If it's true that it compiles with the simple renaming, then yes.
>
> However, your posting is rather unclear.
>
> Why on Earth are you showing the non-problematic code instead of the
> code where there is possibly a problem?


The example code, when compiled with GCC 4.6.1, generates the exact same
error message which was presented by Timon. Therefore, it does appear to
fit the definition of problematic code.


Rui Maciel
 
Reply With Quote
 
Timon Gehr
Guest
Posts: n/a
 
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      12-23-2011
Le 23/12/11 12:04, Timon Gehr a écrit :
> struct B{int foo;};
>
> template<class T> int foo(T x){
> int y = x.foo<1>(0);
> return y;
> }
>
> int main(){
> int c = foo(B());
> }


It is specified in the Gnu standard paragraph 6.6.6:

"Note: Gnu is not foo. Thou shalt not use foo in your programs"

Confirmed for

gcc version 4.2.1 (Apple Inc. build 5664)

in my Mac.

 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      12-23-2011
Marco Minutoli wrote:

> To me this looks like the problematic code .
>
> When we have the template function named bar the line:
> int y = x.foo<1>(0);
>
> is interpreted as:
> int y = (x.foo<1)>(0);
>
> What is not clear to me is why naming foo the template function change
> this behavior.


Probably it's an implicit template instantiation thing. If the definition
of class T is unavailable and the template function invokes x.foo<1>(0),
then maybe it is assumed that class T has a template member function whose
identifier is foo, instead of the code representing a convoluted set of
comparissons between ints.


Rui Maciel
 
Reply With Quote
 
Timon Gehr
Guest
Posts: n/a
 
      12-23-2011
On Dec 23, 3:14*pm, Rui Maciel <(E-Mail Removed)> wrote:
> Marco Minutoli wrote:
> > To me this looks like the problematic code .

>
> > When we have the template function named bar the line:
> > int y = x.foo<1>(0);

>
> > is interpreted as:
> > int y = (x.foo<1)>(0);

>
> > What is not clear to me is why naming foo the template function change
> > this behavior.

>
> Probably it's an implicit template instantiation thing. *If the definition
> of class T is unavailable and the template function invokes x.foo<1>(0),
> then maybe it is assumed that class T has a template member function whose
> identifier is foo, instead of the code representing a convoluted set of
> comparissons between ints.
>
> Rui Maciel


I don't think that holds:

---
template<class T> bool foo(T x){return x.foo<1;} // not
convoluted, does not compile
---
template<class T> bool bar(T x){return x.foo<1>(0);} // convoluted,
compiles as 2 comparisons
struct B{int foo;}; int main(){bar(B());} //
---
 
Reply With Quote
 
Johannes Schaub
Guest
Posts: n/a
 
      12-24-2011
Timon Gehr wrote:

> g++ fails to compile the following code snippet:
> ---
> struct B{int foo;};
>
> template<class T> int foo(T x){
> int y = x.foo<1>(0);
> return y;
> }
>
> int main(){
> int c = foo(B());
> }
> ---
> ---
> bug.cpp: In function ‘int foo(T) [with T = B]’:
> bug.cpp:10:17: instantiated from here
> bug.cpp:5:20: error: ‘foo’ is not a member template function
> ---
>
> The code compiles if the template function is renamed from 'foo' to
> 'bar'.
>
> Is this a bug?


GCC behavior is incorrect. It should accept both.
 
Reply With Quote
 
Miles Bader
Guest
Posts: n/a
 
      12-25-2011
Johannes Schaub <(E-Mail Removed)> writes:
>> The code compiles if the template function is renamed from 'foo' to
>> 'bar'.
>>
>> Is this a bug?

>
> GCC behavior is incorrect. It should accept both.


Hmm, I notice clang gives the same error ....

-miles

--
I'd rather be consing.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
ASP.NET Login control bug or SQL 2005 bug? RedEye ASP .Net 2 12-13-2005 10:57 AM
Re: BUG? OR NOT A BUG? John ASP .Net 2 09-21-2005 10:31 AM
Bug Parade Bug 4953793 Michel Joly de Lotbiniere Java 4 12-02-2003 05:05 AM
how to report bug to g++ ? got a bug and fixed up source code DarkSpy C++ 4 06-27-2003 09:05 AM



Advertisments