Bug #15228 "invalid access to non-static data member" warnings in sql/sql_trigger.cc
Submitted: 24 Nov 2005 14:54 Modified: 2 Nov 2006 14:27
Reporter: Dmitry Lenev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.0.17-bk OS:Linux (Linux)
Assigned to: Dmitry Lenev CPU Architecture:Any

[24 Nov 2005 14:54] Dmitry Lenev
Description:
When you build MySQL with recent enough compiler (GCC 3.3.5 does the trick for me) the following warnings pop up duirng compilation of sql/sql_trigger.cc:

sql_trigger.cc:38: warning: invalid access to non-static data member `
   Table_triggers_list::definitions_list' of NULL object
sql_trigger.cc:38: warning: (perhaps the `offsetof' macro was used incorrectly)
sql_trigger.cc:43: warning: invalid access to non-static data member `
   Table_triggers_list::definition_modes_list' of NULL object
sql_trigger.cc:43: warning: (perhaps the `offsetof' macro was used incorrectly)
sql_trigger.cc:48: warning: invalid access to non-static data member `
   Table_triggers_list::definers_list' of NULL object
sql_trigger.cc:48: warning: (perhaps the `offsetof' macro was used incorrectly)
sql_trigger.cc: In static member function `static bool 
   Table_triggers_list::check_n_load(THD*, const char*, const char*, TABLE*, 
   bool)':
sql_trigger.cc:774: warning: deprecated conversion from string constant to `
   char*'
sql_trigger.cc:869: warning: deprecated conversion from string constant to `
   char*'
sql_trigger.cc: In member function `virtual bool 
   Handle_old_incorrect_sql_modes_hook::process_unknown_string(char*&, char*, 
   MEM_ROOT*, char*)':
sql_trigger.cc:1240: warning: invalid access to non-static data member `
   Table_triggers_list::definition_modes_list' of NULL object
sql_trigger.cc:1240: warning: (perhaps the `offsetof' macro was used 
   incorrectly)

These warnings are caused by the fact that you can't use offsetof() macro with non-POD type according to C++ standard. And Table_triggers_list is far from being POD datatype (particularly because it contains List<> members like definitions_list.

How to repeat:
Just do BUILD/compile-pentium-debug in your source tree
[18 Oct 2006 11:25] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/13856

ChangeSet@1.2238, 2006-10-18 15:28:20+04:00, dlenev@mockturtle.local +3 -0
  Proposed fix for bug#15228 "'invalid access to non-static data member'
  warnings in sql_trigger.cc and sql_view.cc".
  
  According to the current version of C++ stnadard offsetof() macro
  can't be used for non-POD types. So warnings were emitted when we
  tried to use this macro for TABLE_LIST and Table_triggers_list
  classes. Note that despite of these warnings it was probably safe
  thing to do.
  
  This fix tries to circumvent this limitation by using dummy
  instances of these classes (we assume that all instances of
  those classes has same offsets for same members). This hack
  should go away once we will refactor File_parser class.
  
  Alternative approaches such as disabling this warning for
  sql_trigger.cc/sql_view.cc or for the whole server were
  considered less explicit. Also I was unable to find a way
  to disable particular warning for particular _part_ of
  file in GCC.
[19 Oct 2006 7:48] Konstantin Osipov
Approved by email with a comment.
[19 Oct 2006 10:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/13963

ChangeSet@1.2238, 2006-10-19 14:42:22+04:00, dlenev@mockturtle.local +3 -0
  Fix for bug#15228 "'invalid access to non-static data member'
  warnings in sql_trigger.cc and sql_view.cc".
  
  According to the current version of C++ stnadard offsetof() macro
  can't be used for non-POD types. So warnings were emitted when we
  tried to use this macro for TABLE_LIST and Table_triggers_list
  classes. Note that despite of these warnings it was probably safe
  thing to do.
  
  This fix tries to circumvent this limitation by using dummy
  instances of these classes (we assume that all instances of
  those classes has same offsets for same members). This hack
  should go away once we will refactor File_parser class.
  
  Alternative approaches such as disabling this warning for
  sql_trigger.cc/sql_view.cc or for the whole server were
  considered less explicit. Also I was unable to find a way
  to disable particular warning for particular _part_ of
  file in GCC.
[20 Oct 2006 11:44] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/14048

ChangeSet@1.2271, 2006-10-20 15:47:52+04:00, dlenev@mockturtle.local +3 -0
  Fix for bug#15228 "'invalid access to non-static data member'
  warnings in sql_trigger.cc and sql_view.cc".
  
  According to the current version of C++ standard offsetof() macro
  can't be used for non-POD types. So warnings were emitted when we
  tried to use this macro for TABLE_LIST and Table_triggers_list
  classes. Note that despite of these warnings it was probably safe
  thing to do.
  
  This fix tries to circumvent this limitation by implementing
  custom version of offsetof() macro to be used with these
  classes. This hack should go away once we will refactor
  File_parser class.
  
  Alternative approaches such as disabling this warning for
  sql_trigger.cc/sql_view.cc or for the whole server were
  considered less explicit. Also I was unable to find a way
  to disable particular warning for particular _part_ of
  file in GCC.
[2 Nov 2006 14:27] Dmitry Lenev
Fixed in 5.0.29 and 5.1.13

No ChangeLog note required as this bug had no user-visible effects.