diff --git a/include/my_compiler.h b/include/my_compiler.h index ff049f3d8a6..b979b5a5b73 100644 --- a/include/my_compiler.h +++ b/include/my_compiler.h @@ -40,7 +40,15 @@ /* GNU C/C++ */ #if defined __GNUC__ # define MY_ALIGN_EXT -# define MY_ASSERT_UNREACHABLE() __builtin_unreachable() + +/* + __builtin_unreachable() removes the "statement may fall through" warning-as- + error when MY_ASSERT_UNREACHABLE() is used in "case xxx:" in switch (...) + statements. + abort() is there to prevent the execution from reaching the + __builtin_unreachable() as this may cause misleading stack traces. +*/ +# define MY_ASSERT_UNREACHABLE() { abort(); __builtin_unreachable(); } /* Microsoft Visual C++ */ #elif defined _MSC_VER @@ -88,7 +96,7 @@ #endif #ifndef MY_ASSERT_UNREACHABLE -# define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0) +# define MY_ASSERT_UNREACHABLE() do { abort(); } while (0) #endif /** diff --git a/mysql-test/suite/compat/oracle/r/func_to_char.result b/mysql-test/suite/compat/oracle/r/func_to_char.result index a4978b07579..1f95acece5e 100644 --- a/mysql-test/suite/compat/oracle/r/func_to_char.result +++ b/mysql-test/suite/compat/oracle/r/func_to_char.result @@ -439,3 +439,10 @@ NULL 2021-01-24 drop table t1,t2; set @local.sql_mode=@sql_mode; +# +# MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument +# +SELECT TO_CHAR((VALUES('2022-12-12','2020-10-10'))); +ERROR HY000: Illegal parameter data type row for operation 'to_char' +SELECT TO_CHAR((STR_TO_DATE('2023-01-01', '%d-%m-%Y'), 'YYYY-MM-DD') ); +ERROR HY000: Illegal parameter data type row for operation 'to_char' diff --git a/mysql-test/suite/compat/oracle/t/func_to_char.test b/mysql-test/suite/compat/oracle/t/func_to_char.test index 9910fe60a84..7a40321538d 100644 --- a/mysql-test/suite/compat/oracle/t/func_to_char.test +++ b/mysql-test/suite/compat/oracle/t/func_to_char.test @@ -224,3 +224,13 @@ select * from t2; drop table t1,t2; set @local.sql_mode=@sql_mode; +--echo # +--echo # MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TO_CHAR((VALUES('2022-12-12','2020-10-10'))); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT TO_CHAR((STR_TO_DATE('2023-01-01', '%d-%m-%Y'), 'YYYY-MM-DD') ); + diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 9b78d6c159e..1cf1a614ece 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -996,7 +996,10 @@ class Item_func_tochar :public Item_str_func bool check_arguments() const override { - return check_argument_types_can_return_text(1, arg_count); + return + (args[0]->check_type_can_return_date(func_name_cstring()) && + args[0]->check_type_can_return_time(func_name_cstring())) || + check_argument_types_can_return_text(1, arg_count); } public: