From 41779156cb5849a1ad0063cd6cebe2fd5ff74ed9 Mon Sep 17 00:00:00 2001 From: Iakov Kirilenko Date: Mon, 19 Dec 2016 11:39:55 +0300 Subject: [PATCH] Cleanup: fixed compiler warnings, C++11 is on --- global.pri | 7 ++++--- trikControl/src/gyroSensor.cpp | 19 ++++++++++--------- trikControl/src/gyroSensor.h | 9 ++++----- trikControl/trikControl.pro | 3 +-- trikKernel/include/trikKernel/timeVal.h | 2 +- .../src/scriptExecutionControl.cpp | 3 ++- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/global.pri b/global.pri index 2b8079dba..028b2dc66 100644 --- a/global.pri +++ b/global.pri @@ -95,9 +95,10 @@ isEmpty(IS_QSLOG) { LIBS += -lqslog$$CONFIGURATION_SUFFIX } -QMAKE_CXXFLAGS += -std=c++1y -QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual - +QMAKE_CXXFLAGS += -fno-elide-constructors -pedantic-errors -ansi -std=c++11 +#I whant -Werror to be turned on, but Qt has problems +QMAKE_CXXFLAGS += -Wextra -Wcast-qual -Wwrite-strings -Wredundant-decls -Wunreachable-code -Wnon-virtual-dtor -Woverloaded-virtual -Wuninitialized -Winit-self +#-Wold-style-cast -Wmissing-declarations GLOBAL_PWD = $$PWD # Useful function to copy additional files to destination, diff --git a/trikControl/src/gyroSensor.cpp b/trikControl/src/gyroSensor.cpp index 64281a7fb..d1d000976 100644 --- a/trikControl/src/gyroSensor.cpp +++ b/trikControl/src/gyroSensor.cpp @@ -23,8 +23,9 @@ using namespace trikControl; -static const int GYRO_250DPS = 8.75; -static const float RAD_TO_MDEG = 1000 * 180 / M_PI; +static constexpr float GYRO_250DPS = 8.75; +static constexpr double pi() { return std::acos(-1); } +static constexpr float RAD_TO_MDEG = 1000 * 180 / pi(); GyroSensor::GyroSensor(const QString &deviceName, const trikKernel::Configurer &configurer , const trikHal::HardwareAbstractionInterface &hardwareAbstraction) @@ -116,19 +117,19 @@ void GyroSensor::countTilt(QVector gyroData, trikKernel::TimeVal t) mResult[2] = (gyroData[2] - mBias[2]) * GYRO_250DPS; mResult[3] = t.packedUInt32(); - const auto deltaConst = M_PI / 180 / 1000 / 1000000; + constexpr auto deltaConst = pi() / 180 / 1000 / 1000000; const auto dt = (t - mLastUpdate) * deltaConst; const auto x = mResult[0] * dt; const auto y = mResult[1] * dt; const auto z = mResult[2] * dt; - const auto c1 = cos(x / 2); - const auto s1 = sin(x / 2); - const auto c2 = cos(y / 2); - const auto s2 = sin(y / 2); - const auto c3 = cos(z / 2); - const auto s3 = sin(z / 2); + const auto c1 = std::cos(x / 2); + const auto s1 = std::sin(x / 2); + const auto c2 = std::cos(y / 2); + const auto s2 = std::sin(y / 2); + const auto c3 = std::cos(z / 2); + const auto s3 = std::sin(z / 2); QQuaternion deltaQ; deltaQ.setScalar(c1 * c2 * c3 + s1 * s2 * s3); diff --git a/trikControl/src/gyroSensor.h b/trikControl/src/gyroSensor.h index efd278c97..03d1e0145 100644 --- a/trikControl/src/gyroSensor.h +++ b/trikControl/src/gyroSensor.h @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include "gyroSensorInterface.h" @@ -26,7 +26,6 @@ namespace trikKernel { class Configurer; -class TimeVal; } namespace trikHal { @@ -77,20 +76,20 @@ private slots: template static T getPitch(const QQuaternion &q) { - return atan2(2 * q.y()*q.z() + 2 * q.scalar() * q.x() + return std::atan2(2 * q.y()*q.z() + 2 * q.scalar() * q.x() , 1 - 2 * q.x() * q.x() - 2 * q.y() * q.y()); } template static T getRoll(const QQuaternion &q) { - return asin(2 * q.scalar() * q.y() - 2 * q.x() * q.y()); + return std::asin(2 * q.scalar() * q.y() - 2 * q.x() * q.y()); } template static T getYaw(const QQuaternion &q) { - return atan2(2 * q.x() * q.y() + 2 * q.scalar() * q.z() + return std::atan2(2 * q.x() * q.y() + 2 * q.scalar() * q.z() , 1 - 2 * q.y() * q.y() - 2 * q.z() * q.z()); } diff --git a/trikControl/trikControl.pro b/trikControl/trikControl.pro index 6ae501f8b..7053c32c5 100644 --- a/trikControl/trikControl.pro +++ b/trikControl/trikControl.pro @@ -161,8 +161,7 @@ TEMPLATE = lib DEFINES += TRIKCONTROL_LIBRARY -QT += xml gui -QT += multimedia +QT += xml gui multimedia if (equals(QT_MAJOR_VERSION, 5)) { QT += widgets diff --git a/trikKernel/include/trikKernel/timeVal.h b/trikKernel/include/trikKernel/timeVal.h index be247d90a..1c7384a1e 100644 --- a/trikKernel/include/trikKernel/timeVal.h +++ b/trikKernel/include/trikKernel/timeVal.h @@ -13,7 +13,7 @@ * limitations under the License. */ #pragma once - +#include namespace trikKernel { /// Structure of a time value in a convenient format. diff --git a/trikScriptRunner/src/scriptExecutionControl.cpp b/trikScriptRunner/src/scriptExecutionControl.cpp index c56b2aa20..6d4b26140 100644 --- a/trikScriptRunner/src/scriptExecutionControl.cpp +++ b/trikScriptRunner/src/scriptExecutionControl.cpp @@ -102,7 +102,8 @@ void ScriptExecutionControl::system(const QString &command, bool synchronously) QProcess::startDetached("sh", args); } else { QLOG_INFO() << "Running synchronously: " << command; - ::system(command.toStdString().c_str()); + auto rc = ::system(command.toStdString().c_str()); + QLOG_INFO() << "System result code: " << rc; } }