Commit 1a793de9 authored by unknown's avatar unknown

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.


sql/parse_file.h:
  Introduced auxillary macro which can be used instead of offsetof()
  to get offsets of members in class for non-POD types without getting
  warnings (assuming that all instances of the class has same offsets
  for same members).
sql/sql_trigger.cc:
  Use my_offsetof() macro instead of standard offsetof() macro with
  Table_triggers_list class in order to avoid warnings (offsetof()
  cannot be used for non-POD types according to the standard).
sql/sql_view.cc:
  Use my_offsetof() macro instead of standard offsetof() macro with
  TABLE_LIST class in order to avoid warnings (offsetof() cannot
  be used for non-POD types according to the standard).
parent 00fca9ea
......@@ -107,4 +107,20 @@ class File_parser: public Sql_alloc
bool bad_format_errors);
};
/*
Custom version of standard offsetof() macro which can be used to get
offsets of members in class for non-POD types (according to the current
version of C++ standard offsetof() macro can't be used in such cases and
attempt to do so causes warnings to be emitted, OTOH in many cases it is
still OK to assume that all instances of the class has the same offsets
for the same members).
This is temporary solution which should be removed once File_parser class
and related routines are refactored.
*/
#define my_offsetof(TYPE, MEMBER) \
((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10))
#endif /* _PARSE_FILE_H_ */
......@@ -36,17 +36,17 @@ static File_option triggers_file_parameters[]=
{
{
{(char *) STRING_WITH_LEN("triggers") },
offsetof(class Table_triggers_list, definitions_list),
my_offsetof(class Table_triggers_list, definitions_list),
FILE_OPTIONS_STRLIST
},
{
{(char *) STRING_WITH_LEN("sql_modes") },
offsetof(class Table_triggers_list, definition_modes_list),
my_offsetof(class Table_triggers_list, definition_modes_list),
FILE_OPTIONS_ULLLIST
},
{
{(char *) STRING_WITH_LEN("definers") },
offsetof(class Table_triggers_list, definers_list),
my_offsetof(class Table_triggers_list, definers_list),
FILE_OPTIONS_STRLIST
},
{ { 0, 0 }, 0, FILE_OPTIONS_STRING }
......@@ -55,7 +55,7 @@ static File_option triggers_file_parameters[]=
File_option sql_modes_parameters=
{
{(char*) STRING_WITH_LEN("sql_modes") },
offsetof(class Table_triggers_list, definition_modes_list),
my_offsetof(class Table_triggers_list, definition_modes_list),
FILE_OPTIONS_ULLLIST
};
......
......@@ -582,40 +582,40 @@ static const int num_view_backups= 3;
*/
static File_option view_parameters[]=
{{{(char*) STRING_WITH_LEN("query")},
offsetof(TABLE_LIST, query),
my_offsetof(TABLE_LIST, query),
FILE_OPTIONS_ESTRING},
{{(char*) STRING_WITH_LEN("md5")},
offsetof(TABLE_LIST, md5),
my_offsetof(TABLE_LIST, md5),
FILE_OPTIONS_STRING},
{{(char*) STRING_WITH_LEN("updatable")},
offsetof(TABLE_LIST, updatable_view),
my_offsetof(TABLE_LIST, updatable_view),
FILE_OPTIONS_ULONGLONG},
{{(char*) STRING_WITH_LEN("algorithm")},
offsetof(TABLE_LIST, algorithm),
my_offsetof(TABLE_LIST, algorithm),
FILE_OPTIONS_ULONGLONG},
{{(char*) STRING_WITH_LEN("definer_user")},
offsetof(TABLE_LIST, definer.user),
my_offsetof(TABLE_LIST, definer.user),
FILE_OPTIONS_STRING},
{{(char*) STRING_WITH_LEN("definer_host")},
offsetof(TABLE_LIST, definer.host),
my_offsetof(TABLE_LIST, definer.host),
FILE_OPTIONS_STRING},
{{(char*) STRING_WITH_LEN("suid")},
offsetof(TABLE_LIST, view_suid),
my_offsetof(TABLE_LIST, view_suid),
FILE_OPTIONS_ULONGLONG},
{{(char*) STRING_WITH_LEN("with_check_option")},
offsetof(TABLE_LIST, with_check),
my_offsetof(TABLE_LIST, with_check),
FILE_OPTIONS_ULONGLONG},
{{(char*) STRING_WITH_LEN("revision")},
offsetof(TABLE_LIST, revision),
my_offsetof(TABLE_LIST, revision),
FILE_OPTIONS_REV},
{{(char*) STRING_WITH_LEN("timestamp")},
offsetof(TABLE_LIST, timestamp),
my_offsetof(TABLE_LIST, timestamp),
FILE_OPTIONS_TIMESTAMP},
{{(char*)STRING_WITH_LEN("create-version")},
offsetof(TABLE_LIST, file_version),
my_offsetof(TABLE_LIST, file_version),
FILE_OPTIONS_ULONGLONG},
{{(char*) STRING_WITH_LEN("source")},
offsetof(TABLE_LIST, source),
my_offsetof(TABLE_LIST, source),
FILE_OPTIONS_ESTRING},
{{NullS, 0}, 0,
FILE_OPTIONS_STRING}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment