public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* RTTI names for classes in anonymous namespaces
@ 2023-08-23  8:40 Varun Kumar E
  2023-08-23  8:54 ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Varun Kumar E @ 2023-08-23  8:40 UTC (permalink / raw)
  To: libstdc++

[-- Attachment #1: Type: text/plain, Size: 1096 bytes --]

 hello all,

      The RTTI names generated by gcc for classes in anonymous namespaces
begin with the prefix asterisk(*).
      Once the __name pointer is different why do we not return
immediately? Instead we perform a string comparison if the name does not
begin with asterisk(*).
      Could you please explain the reasoning behind this.

      code snippet below:

   type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT
  {
      if (std::__is_constant_evaluated())
         return this == &__arg;

      if (__name == __arg.__name)
         return true;

      #if !__GXX_TYPEINFO_EQUALITY_INLINE
         // ABI requires comparisons to be non-inline.
         return __equal(__arg);
     #elif !__GXX_MERGED_TYPEINFO_NAMES
         // Need to do string comparison.
         return __name[0] != '*' && __builtin_strcmp (__name, __arg.name())
== 0;
      #else
         return false;
      #endif
     }

     Code link: typeinfo - gcc-mirror/gcc - Sourcegraph
<https://sourcegraph.com/github.com/gcc-mirror/gcc/-/blob/libstdc++-v3/libsupc++/typeinfo?L205>


regards,
Varun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTTI names for classes in anonymous namespaces
  2023-08-23  8:40 RTTI names for classes in anonymous namespaces Varun Kumar E
@ 2023-08-23  8:54 ` Jonathan Wakely
  2023-08-23  8:59   ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2023-08-23  8:54 UTC (permalink / raw)
  To: Varun Kumar E; +Cc: libstdc++

[-- Attachment #1: Type: text/plain, Size: 1827 bytes --]

On Wed, 23 Aug 2023, 09:41 Varun Kumar E via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

>  hello all,
>
>       The RTTI names generated by gcc for classes in anonymous namespaces
> begin with the prefix asterisk(*).
>       Once the __name pointer is different why do we not return
> immediately? Instead we perform a string comparison if the name does not
> begin with asterisk(*).
>

This would have been more more useful as a reply to your previous email on
the subject (which I already replied to) rather than a separate thread.

When using shared objects there is no guarantee that duplicate RTTI data
gets combined, so we can have two or more copies of the data for a single
type. Using strcmp to compare the names works correctly in this case.

For types in anonymous namespaces (or types with no linkage) the type
cannot exist in two different shared objects, so we know that the RTTI data
is unique. That means a pointer comparison is ok.


      Could you please explain the reasoning behind this.
>
>       code snippet below:
>
>    type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT
>   {
>       if (std::__is_constant_evaluated())
>          return this == &__arg;
>
>       if (__name == __arg.__name)
>          return true;
>
>       #if !__GXX_TYPEINFO_EQUALITY_INLINE
>          // ABI requires comparisons to be non-inline.
>          return __equal(__arg);
>      #elif !__GXX_MERGED_TYPEINFO_NAMES
>          // Need to do string comparison.
>          return __name[0] != '*' && __builtin_strcmp (__name, __arg.name
> ())
> == 0;
>       #else
>          return false;
>       #endif
>      }
>
>      Code link: typeinfo - gcc-mirror/gcc - Sourcegraph
> <
> https://sourcegraph.com/github.com/gcc-mirror/gcc/-/blob/libstdc++-v3/libsupc++/typeinfo?L205
> >
>
>
> regards,
> Varun
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTTI names for classes in anonymous namespaces
  2023-08-23  8:54 ` Jonathan Wakely
@ 2023-08-23  8:59   ` Jonathan Wakely
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2023-08-23  8:59 UTC (permalink / raw)
  To: Varun Kumar E; +Cc: libstdc++

[-- Attachment #1: Type: text/plain, Size: 2193 bytes --]

On Wed, 23 Aug 2023, 09:54 Jonathan Wakely, <jwakely.gcc@gmail.com> wrote:

>
>
> On Wed, 23 Aug 2023, 09:41 Varun Kumar E via Libstdc++, <
> libstdc++@gcc.gnu.org> wrote:
>
>>  hello all,
>>
>>       The RTTI names generated by gcc for classes in anonymous namespaces
>> begin with the prefix asterisk(*).
>>       Once the __name pointer is different why do we not return
>> immediately? Instead we perform a string comparison if the name does not
>> begin with asterisk(*).
>>
>
> This would have been more more useful as a reply to your previous email on
> the subject (which I already replied to) rather than a separate thread.
>
> When using shared objects there is no guarantee that duplicate RTTI data
> gets combined, so we can have two or more copies of the data for a single
> type. Using strcmp to compare the names works correctly in this case.
>
> For types in anonymous namespaces (or types with no linkage) the type
> cannot exist in two different shared objects, so we know that the RTTI data
> is unique. That means a pointer comparison is ok.
>


And as I said in the other thread, the asterisk is present when the pointer
comparison is ok.

If either name begins with * then it's a type that only exists in one
object file, and so its RTTI data is unique.



>
>       Could you please explain the reasoning behind this.
>>
>>       code snippet below:
>>
>>    type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT
>>   {
>>       if (std::__is_constant_evaluated())
>>          return this == &__arg;
>>
>>       if (__name == __arg.__name)
>>          return true;
>>
>>       #if !__GXX_TYPEINFO_EQUALITY_INLINE
>>          // ABI requires comparisons to be non-inline.
>>          return __equal(__arg);
>>      #elif !__GXX_MERGED_TYPEINFO_NAMES
>>          // Need to do string comparison.
>>          return __name[0] != '*' && __builtin_strcmp (__name, __arg.name
>> ())
>> == 0;
>>       #else
>>          return false;
>>       #endif
>>      }
>>
>>      Code link: typeinfo - gcc-mirror/gcc - Sourcegraph
>> <
>> https://sourcegraph.com/github.com/gcc-mirror/gcc/-/blob/libstdc++-v3/libsupc++/typeinfo?L205
>> >
>>
>>
>> regards,
>> Varun
>>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RTTI names for classes in anonymous namespaces.
  2023-08-23  8:19 Varun Kumar E
@ 2023-08-23  8:48 ` Jonathan Wakely
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2023-08-23  8:48 UTC (permalink / raw)
  To: Varun Kumar E; +Cc: libstdc++

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On Wed, 23 Aug 2023, 09:19 Varun Kumar E via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

>  hello all,
>
>       The RTTI names generated by gcc for classes in anonymous namespaces
> begin with the prefix asterisk(*).

      Could you please explain the reasoning behind this?


It means that type_info equality can be determined by just comparing the
const char* pointers, instead of using strcmp to match equal names.

The pointer value will be unique, so will only compare equal to itself.


As Itanium ABI
> c++ has no mention of this.
>

The Itanium ABI doesn't dictate the form of those strings.

When you call std::type_info::name() the '*' is not in the result. It's
just an implementation detail.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RTTI names for classes in anonymous namespaces.
@ 2023-08-23  8:19 Varun Kumar E
  2023-08-23  8:48 ` Jonathan Wakely
  0 siblings, 1 reply; 5+ messages in thread
From: Varun Kumar E @ 2023-08-23  8:19 UTC (permalink / raw)
  To: libstdc++

[-- Attachment #1: Type: text/plain, Size: 239 bytes --]

 hello all,

      The RTTI names generated by gcc for classes in anonymous namespaces
begin with the prefix asterisk(*).
      Could you please explain the reasoning behind this? As Itanium ABI
c++ has no mention of this.

regards,
Varun

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-23  9:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23  8:40 RTTI names for classes in anonymous namespaces Varun Kumar E
2023-08-23  8:54 ` Jonathan Wakely
2023-08-23  8:59   ` Jonathan Wakely
  -- strict thread matches above, loose matches on Subject: below --
2023-08-23  8:19 Varun Kumar E
2023-08-23  8:48 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).