Category Archives: sqlpp11

sqlpp11-0.42 released: Improved compile-time error messages for MSVC

Since end of 2015, sqlpp11 can be compiled with MSVC. When people started using it, it turned out that some of the carefully crafted static_assert messages were not shown by MSVC.

What’s happening? Here is a simplified example:

 

While clang and gcc show the static_assert message and the information that int is not a struct and therefore certainly does not have a member cheesecake, MSVC just tells you the latter.

Compiled with /EHsc /nologo /W4 /c
main.cpp
main.cpp(9): error C2228: left of ‘.cheesecake’ must have class/struct/union
main.cpp(9): note: type is ‘void’

That’s it. No message about the failing static_assert.

This actually is a nice feature, which can help to reduce the compiler spew. The return type of function does not match the way it is used, so why bother looking into the details of the function?

But in real life, e.g. in older versions of sqlpp11, this can lead to trouble. For instance the following code

sqlpp11 will reject this query at compile time, because the where condition is missing, which is likely to be an oversight (aka bug).

Clang and gcc users get an error message like this:

error: static_assert failed “calling where() or unconditionally() required”

However, MSVC just says:

error C3313: ‘count’: variable cannot have the type ‘void’

sqlpp11-0.42 and later remedies that by replacing void with better failure return types,e.g. assert_where_or_unconditionally_called_t. This ensures that errors can be comprehended, even if the static_assert is message is not presented by the compiler.

I will give more details about the techniques being used and how this can be utilized for testing in my talk at CppCon: “How to test static_assert?”

 

sqlpp11-0.30 released

This is the first release of sqlpp11 since early October and the library has undergone quite a few changes. Some of those are listed below:

Functional Changes:

  • Preprocessor generator for columns/tables. Thanks niXman!
  • Added custom query command. This allows you to combine building blocks of sqlpp11 into custom queries, for instance a SELECT..INTO:
  • Added UNION clause
  • Added WITH clause and Common Table Expressions
  • Better understanding of names by the library. Any two entities (e.g. columns) with the same name, now also share a common type representing this name, see also section “Migration”. This leads to more stringent compile time tests.

The documentation for those major changes and a few minor additions will follow in the Wiki over the next few weeks. Until then, the tests and examples from the repository will have to do 🙂

Misc:

  • Less lengthy template error messages. Applying the techniques shown in the talk mentioned above reduced the amount of error messages a lot.
  • Warning free compilation even with -Wconversion, -Wpedantic and -Wshadow, thanks TyRoXx!

Caveat:

    Attempting to compile sqlpp11 with clang-3.1 crashes the compiler.

Migration:

If you are using an older version of sqlpp11,  you will have to update your code generator.  This is what a new column looks like

Here’s an old version for comparison:

Switching to the preprocessor code (see above) might also be an option.