[PATCH] generalized range_query class for multiple contexts

Martin Sebor msebor@gmail.com
Thu Sep 24 17:10:16 GMT 2020


On 9/24/20 12:46 AM, Aldy Hernandez wrote:
> 
> 
> On 9/24/20 1:53 AM, Martin Sebor wrote:
> 
>> Finally, unless both a type and function with the same name exist
>> in the same scope there is no reason to mention the class-id when
>> referencing a class name.  I.e., this
>>
>>    value_range_equiv *allocate_value_range_equiv ();
>>    void free_value_range_equiv (value_range_equiv *);
>>
>> is the same as this:
>>
>>    class value_range_equiv *allocate_value_range_equiv ();
>>    void free_value_range_equiv (class value_range_equiv *);
>>
>> but the former is shorter and clearer (and in line with existing
>> practice).
> 
> value_range_equiv may not be defined in the scope of range-query.h, so 
> that is why the class specifier is there.

I see.  It's probably a reflection of my C++ background that this
style catches my eye.  In C++ I think it's more common to introduce
a forward declaration of a class before using it.

Just as a side note, the first declaration of a type introduces it
into the enclosing namespace so that from that point forward it can
be used without the class-id.  E.g., this is valid:

   struct A
   {
     // Need class here...
     class B *f ();
     // ...but not here...
     void g (B *);
   };

  // ...or even here:
  B* A::f () { return 0; }

Either way, the code is correct as is and I don't object to it,
just noting that (at least some of) the class-ids are redundant.

Martin


More information about the Gcc-patches mailing list