[odb-users] Re: Problem: Generated unfinished -odb.cxx with unimplemented pure virtual function

xuewen wang xuewen.ok at gmail.com
Wed May 15 02:35:42 EDT 2024


More details:
Dear ODB Compiler Team,

I hope this message finds you well. I am currently working on a project
involving the ODB compiler and have encountered some issues related to the
handling of pure virtual functions in inherited classes. I would appreciate
your assistance in addressing these concerns.

1. **Non-Generation of Query Functions for Derived Classes with Pure
Virtual Functions:**
   In my code, I have a base class  Person  with a pure virtual function
 test() . The derived class  Student , which is also an ODB-managed object,
does not seem to have query functions generated by ODB when there is a pure
virtual function in the parent class.

   class Person {
   public:
       virtual void test() = 0;
   };

   #pragma db object
   class Student : public Person {
   public:
       #pragma db id auto
       int id;
   };

2. **Lack of Compiler Warnings or Errors for Unimplemented Pure Virtual
Functions:**
   When I forget to implement the pure virtual function  test()  in the
derived class  Student , the ODB compiler neither issues a warning nor an
error during compilation. This omission leads to compiling issues of target
project that are difficult to trace back to the source.

3. **Suggestion for Improvement:**
   It would be highly beneficial for developers if the ODB compiler could
provide a warning or error when query functions are omitted due to the
presence of unimplemented pure virtual functions in derived classes. Write
comments in the generated source code to tell that there are unimplemented
pure functions in the base class. These features would help avoid potential
runtime problems and improve code reliability.

Could you please provide guidance on whether there are existing compiler
options that I might have missed which address these issues? Additionally,
your thoughts on the possibility of enhancing the compiler to handle such
cases more transparently would be greatly appreciated.

Thank you for your time and assistance. I look forward to your response.
Best regards...
---- Sean Wang (Xuewen Wang), Beijing, China.


On Tue, May 14, 2024 at 11:14 PM xuewen wang <xuewen.ok at gmail.com> wrote:

> Compiler version: obd 2.5.0-b.25+1
> Building environment: build2 on ubuntu 22.04.4LTS
> GCC version: gcc 11.04
>
> Issue: the odb compiler doesn't finish generating the -odb.cxx file
> it stops after generating the init functions.
> To reproduce the problem, compile the Persion.h with the following command
> line:
> odb --database sqlite --generate-query --generate-schema --std c++11
> Persion.h
>
> The Person.h file:
> //=============================================
> class Person {
> public:
>     virtual void test() = 0;
> };
>
>
> #pragma db object
> class Student : public Person {
> public:
>     int id;
> };
> //=============================================
>
> The tail of generated Persion-odb.cxx:
> //=============================================
> ......
>   void access::object_traits_impl< ::Student, id_sqlite >::
>   init (object_type& o,
>         const image_type& i,
>         database* db)
>   {
>     ODB_POTENTIALLY_UNUSED (o);
>     ODB_POTENTIALLY_UNUSED (i);
>     ODB_POTENTIALLY_UNUSED (db);
>
>     // id
>     //
>     {
>       int& v =
>         o.id;
>
>       sqlite::value_traits<
>           int,
>           sqlite::id_integer >::set_value (
>         v,
>         i.id_value,
>         i.id_null);
>     }
>   }
> }
>
> #include <odb/post.hxx>
> //==============================================
> Best regards...
> ---- Sean Wang (Xuewen Wang), Beijing, China.
>


More information about the odb-users mailing list