Hi colleagues,

The follow program is an abstraction of on application where it
produce an error in runtime and i don't know why it's success.

The program compile very good in all cases with Visual Studio 2005,
2008, 2010, MinGW 4.5.1 on Windows 7 and with GCC 4.3 on GNU Debian.
Though, it produce an error in runtime when it's compiled with MinGW
or GCC and next it's executed.

Anybody can help me to distinguish whether it's an error of my source
code or a bug of gcc?

=================== source code ===================

  template <class T>
  class reference
    {
      public:
        reference(T& p)
        {
        }
    };

  struct schema
    {
    };

  template <typename T>
  struct schema_descriptor
    {
      typedef schema type;
    };

  template <typename T>
  inline schema* type_schema()
    {
      typedef typename schema_descriptor<T>::type type_type;
      static type_type result;
      return &result;
    };

  template <typename T>
  struct reference_schema : schema
    {
      reference_schema():
        schema()
        {
          schema* _delegate = type_schema<T>();
        }
    };

  struct basic_schema : schema
    {
      public:
        template <typename S, typename D, typename C>
        void caster()
          {
            schema *src = type_schema<S>();
          }
    };

  template<typename T>
  struct object_schema : basic_schema
    {
      template <typename I>
      void implements()
        {
          typedef reference<T> my_ref;
          typedef reference<I> their_ref;

          caster<my_ref, their_ref, int>();
        }
    };

  template <typename T>
  struct dynamic_object_schema : object_schema<T>
    {
      dynamic_object_schema()
        {
          this->template implements<int>();
        }
    };

  class sponge_object
    {
    };

  struct sponge_object_schema : dynamic_object_schema<sponge_object>
    {
    };

  template <>
  struct schema_descriptor<sponge_object>
    {
      typedef sponge_object_schema type;
    };

  template <>
  struct schema_descriptor< reference<sponge_object> >
    {
      typedef reference_schema<sponge_object> type;
    };

int main()
  {
    reference_schema <sponge_object> exploit;
    return 0;
  }
=================== source code ===================

I began to debug the source code with GDB and this is the result
that i got.

1 - reference_schema <sponge_object>

      // it's specialize
2   - type_schema <sponge_object>

3     - sponge_object_schema

4       - dynamic_object_schema <sponge_object>

5         - object_schema <sponge_object>::implements <IDynamicObject>();

6           - basic_schema::caster <reference<sponge_object>, 
reference<IDynamicObject>, ...>();

                // it's specialize
7             - type_schema < reference <sponge_object> >

                  // at this point it begin to repeat
8               - reference_schema <sponge_object>

                    // here it exploit and i don't know why
                    // if it's a static declaration
9                 - type_schema <sponge_object>

Like you see, the points 1 and 8 are equal, and then 2 and 9 are equal
too, but the static declaration inside 'type_schema'

      static type_type result;

don't have to created again, since it's created already in the point
2, because it's a static declaration. In GNU Debian Linux it's produce
the error:

terminate called after throwing an instance of
'--gnu_cxx::recursive_init_error' what : std::exceptions.

and in Windows it stay sleeping until the application is closed by
Windows.

-- 
Best regards,
 Gilberto Cuba Ricardo

PD: Sorry for the long extension of the message and for my bad
english.

Reply via email to