sqlpp17
sqlpp17 copied to clipboard
order of evaluation problem
Hi,
I found there are some code like:
struct
{
bool first = true;
[[nodiscard]] auto to_string() -> std::string
{
if (first)
{
first = false;
return "";
}
else
{
return ", ";
}
}
} separator;
return (std ::string{} + ... + (separator.to_string() + to_sql_column_spec_string(context, ColumnSpecs{})));
https://github.com/rbock/sqlpp17/blob/6f7a0f485a37adfd755f627bd98ab3721b498cb4/connectors/postgresql/include/sqlpp17/postgresql/clause/create_table.h#L84
Such code might be undefined behavior due to the order of evaluation
By the standard, the first separator("") could be introduced to any place between the columns. For gcc, the empty separator is place to the back of the line.
Here is a demo of such bug on ideone.
Thanks,
Thanks for the report. I obviously got confused with some of the new rules.
It seems I could use the comma operator in a fold expression instead.