Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #12753 > unrolled thread
| Started by | Timon Gehr <timon.gehr@gmail.com> |
|---|---|
| First post | 2011-12-23 03:04 -0800 |
| Last post | 2011-12-25 11:36 +0900 |
| Articles | 11 — 7 participants |
Back to article view | Back to comp.lang.c++
bug in gcc? Timon Gehr <timon.gehr@gmail.com> - 2011-12-23 03:04 -0800
Re: bug in gcc? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2011-12-23 12:28 +0100
Re: bug in gcc? Timon Gehr <timon.gehr@gmail.com> - 2011-12-23 04:33 -0800
Re: bug in gcc? Rui Maciel <rui.maciel@gmail.com> - 2011-12-23 13:21 +0000
Re: bug in gcc? Timon Gehr <timon.gehr@gmail.com> - 2011-12-23 05:36 -0800
Re: bug in gcc? Marco Minutoli <mminutoli@gmail.com> - 2011-12-23 14:50 +0100
Re: bug in gcc? Rui Maciel <rui.maciel@gmail.com> - 2011-12-23 14:14 +0000
Re: bug in gcc? Timon Gehr <timon.gehr@gmail.com> - 2011-12-23 06:30 -0800
Re: bug in gcc? jacob navia <jacob@spamsink.net> - 2011-12-23 14:43 +0100
Re: bug in gcc? Johannes Schaub <schaub.johannes@googlemail.com> - 2011-12-24 17:22 +0100
Re: bug in gcc? Miles Bader <miles@gnu.org> - 2011-12-25 11:36 +0900
| From | Timon Gehr <timon.gehr@gmail.com> |
|---|---|
| Date | 2011-12-23 03:04 -0800 |
| Subject | bug in gcc? |
| Message-ID | <d304891e-05dc-44f1-9df0-19ada4117dbb@g41g2000yqa.googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2011-12-23 12:28 +0100 |
| Message-ID | <jd1olu$1ge$1@dont-email.me> |
| In reply to | #12753 |
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
[toc] | [prev] | [next] | [standalone]
| From | Timon Gehr <timon.gehr@gmail.com> |
|---|---|
| Date | 2011-12-23 04:33 -0800 |
| Message-ID | <6e832226-5159-4e78-96f6-d20d5114c48c@p13g2000yqd.googlegroups.com> |
| In reply to | #12754 |
On Dec 23, 12:28 pm, "Alf P. Steinbach" <alf.p.steinbach
+use...@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2011-12-23 13:21 +0000 |
| Message-ID | <jd1v7t$l8b$1@speranza.aioe.org> |
| In reply to | #12754 |
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
[toc] | [prev] | [next] | [standalone]
| From | Timon Gehr <timon.gehr@gmail.com> |
|---|---|
| Date | 2011-12-23 05:36 -0800 |
| Message-ID | <d203c79c-d5c3-4717-825d-f0399ff9614e@u6g2000vbg.googlegroups.com> |
| In reply to | #12761 |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51664
[toc] | [prev] | [next] | [standalone]
| From | Marco Minutoli <mminutoli@gmail.com> |
|---|---|
| Date | 2011-12-23 14:50 +0100 |
| Message-ID | <87ipl7flda.fsf@gmail.com> |
| In reply to | #12754 |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> writes:
> 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?
>
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.
BTW I have tested it with both g++ and clang++ and both behave in the
same way.
> 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
Cheers,
Marco.
[toc] | [prev] | [next] | [standalone]
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Date | 2011-12-23 14:14 +0000 |
| Message-ID | <jd22bp$t0s$1@speranza.aioe.org> |
| In reply to | #12765 |
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
[toc] | [prev] | [next] | [standalone]
| From | Timon Gehr <timon.gehr@gmail.com> |
|---|---|
| Date | 2011-12-23 06:30 -0800 |
| Message-ID | <028b6778-07df-4fbb-9438-599cfd0d2a3b@f15g2000yqo.googlegroups.com> |
| In reply to | #12766 |
On Dec 23, 3:14 pm, Rui Maciel <rui.mac...@gmail.com> 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());} //
---
[toc] | [prev] | [next] | [standalone]
| From | jacob navia <jacob@spamsink.net> |
|---|---|
| Date | 2011-12-23 14:43 +0100 |
| Message-ID | <jd20hd$obm$1@speranza.aioe.org> |
| In reply to | #12753 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Johannes Schaub <schaub.johannes@googlemail.com> |
|---|---|
| Date | 2011-12-24 17:22 +0100 |
| Message-ID | <jd4qj2$p91$1@news.albasani.net> |
| In reply to | #12753 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Miles Bader <miles@gnu.org> |
|---|---|
| Date | 2011-12-25 11:36 +0900 |
| Message-ID | <87ipl5v0lj.fsf@catnip.gol.com> |
| In reply to | #12789 |
Johannes Schaub <schaub.johannes@googlemail.com> 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web