This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA] linespec.c change to stop "malformed template specification" error


Jim Blandy <jimb@zwingli.cygnus.com> writes:

> Elena Zannoni <ezannoni@cygnus.com> writes:
>>  > Operators like '<' can appear in template arguments.  For example, you
>>  > could define a template like this:
>>  > 
>>  >         template <int i> struct list { int a[i], b[i]; };
>>  > 
>>  > and then use it like this:
>>  > 
>>  >         struct list <20> l;
>>  > 
>>  > and you get the same thing as if you'd written:
>>  > 
>>  >         struct { int a[20], b[20]; } l;
>>  > 
>>  > At least I think so, anyway.  I don't really know C++.  But the point
>>  > is, those template arguments can be any arbitrary constant expression.
>>  > So I could have a template invocation like this:
>>  > 
>>  >         struct list < (x < y) ? 10 : 20 > l;
>>  > 
>>  > So how does our poor little decode_line_1 handle that?  Basically, we
>>  > need to replace decode_line_1 with a real parser.
>> 
>> I am not sure that decode_line_1 will ever be invoked in such a case.
>> Looking at when it's called, it seems to be only when you specify 
>> a location, not an expression, and that occurs for 'break blah' and 
>> 'list blah' only.
> 
> Templates can expand to functions, too:
> 
> template <int i>
> int add_const (int j)
> {
>   return i + j;
>}
> 
> then, add_const <4> (3) returns 7.
> 
> But add_const <4> and add_const <5> are different functions.  The
> compiler emits separate code for each of them.  So you need to be able
> to set a breakpoint on add_const <4>.  And the template argument to
> add_const can be any constant expression.
> 
> So finding breakpoint names requires parsing (almost) arbitrary
> expressions.
Only if you allow arbitrary names.
We don't.
So this leaves allowing a superset.


-- 
"I went to the cinema, and the prices were:  Adults $5.00,
children $2.50.  So I said, "Give me two boys and a girl."
"-Steven Wright


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]