Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SOCI_OVERRIDE macro as conditional C++11 override specifier #596

Merged
merged 1 commit into from
Sep 24, 2017
Merged

Add SOCI_OVERRIDE macro as conditional C++11 override specifier #596

merged 1 commit into from
Sep 24, 2017

Conversation

mloskot
Copy link
Contributor

@mloskot mloskot commented Sep 24, 2017

MSVC++ 1900+ always compile with C++11 mode enabled, so it should be safe to selectively enable 'override'specifier for internal use.

It does not enable all C++11 features for SOCI and we still compile with C++11 compilation mode SOCI_CXX_C11=OFF by default.


Refactoring Procedure with clang-tidy

  • Install clang-tidy as new as you can easily get
$ clang-tidy-4.0 --version
LLVM (http://llvm.org/):
  LLVM version 4.0.0

  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: haswell
  • Generate compile command database (compile_commands.json) with CMake (sweet, isn't it? :-))
$ cd soci
$ mkdir build
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSOCI_CXX_C11=ON .. 

# All backends configured!
  • Run clang-tidy with modernize-use-override check on all translations units and actually refactor all the code (-fix)
$ /usr/lib/llvm-4.0/share/clang/run-clang-tidy.py -clang-tidy-binary \
       -header-filter='.*' -checks='-*,modernize-use-modernize' -fix

Here we use run-clang-tidy.py
utility script and run inside the directory with compile_commands.json database.
The script is recommended way to run clang-tidy, it runs concurrent executions, etc,

  • Finally, use your favourite tool to run case-sensitive whole-word search for override and replace with SOCI_OVERRIDE.

Voilà!

Copy link
Member

@vadz vadz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks, the extra safety of using override is always nice to have.

@@ -95,6 +95,12 @@ namespace std {
// mode, we just need to check for the minimal compiler version supporting them
// (see https://msdn.microsoft.com/en-us/library/hh567368.aspx).

#if defined(SOCI_HAVE_CXX_C11) || (defined(_MSC_VER) && _MSC_VER >= 1800)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, hardly important, but it is actually supposed to work with 1700 (VC11) too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should even, partially or perhaps work with MSVC 1600 as per Support For C++11/14/17 Features.

@@ -135,20 +135,20 @@ struct empty_rowid_backend : details::rowid_backend
{
empty_rowid_backend(empty_session_backend &session);

~empty_rowid_backend();
~empty_rowid_backend() SOCI_OVERRIDE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I'm personally for using override on dtors too but this is recommended against by C++ core guidelines, see this closed issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting reading. I've started using the CppCoreGuidelines, but not relying on it strictly due to the performance issues (eg. with gsl::span).

Meanwhile, I agree with your comment in that thread.

For now, I'll stick SOCI_OVERRIDE in destructors. After we move to C++11 only and we ever start using the CppCoreGuidelines or discuss/agree to do otherwise. we can always remove it.

@mloskot
Copy link
Contributor Author

mloskot commented Sep 24, 2017

I've run override refactoring across the whole codebase and updated the PR.

MSVC++ 1900+ always compile with C++11 mode enabled, so it should be
safe to selectively enable 'override'specifier for internal use.

It does not enable all C++11 features for SOCI and we still compile
with C++11 compilation mode SOCI_CXX_C11=OFF by default.

Refactoring performed with clang-tidy-4.0:

 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DSOCI_CXX_C11=ON ..
 run-clang-tidy.py -clang-tidy-binary -header-filter='.*' \
                   -checks='-*,modernize-use-modernize' -fix
@mloskot mloskot merged commit 3d32f52 into SOCI:master Sep 24, 2017
@mloskot mloskot deleted the ml/macro-soci-override branch September 24, 2017 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants