From 17391fa4a29d388c3c54b0202f1071d570d09541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jason=20Mar=C3=A9chal?= <45510813+JasonMarechal25@users.noreply.github.com> Date: Tue, 12 Dec 2023 11:16:27 +0100 Subject: [PATCH] Enable cpp20 (#1799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Unable c++20 * Test code for c++ 20 * temp centos CI * Tmp oracle CI * Use gcc 10 in centos * Use gcc 10 on oracle 8 * Use gcc 10 for sonar * Format * Fix infinite recursion in cpp20 for CString==char* * Sonar fix * Remove some operator overload for CString * Revert "Remove some operator overload for CString" This reverts commit 718083f502ff536f5255e41206b792b08be094e5. * Fix windows build * Remove test code * Only build centOS and oracle on develop * const corectness Co-authored-by: Florian Omnès <26088210+flomnes@users.noreply.github.com> --------- Co-authored-by: Jason Marechal Co-authored-by: Florian Omnès <26088210+flomnes@users.noreply.github.com> --- .github/workflows/centos7.yml | 13 +++++-- .github/workflows/oracle8.yml | 10 ++--- .github/workflows/sonarcloud.yml | 39 ++++++++++--------- .../workflows/ubuntu-system-deps-build.yml | 3 +- .github/workflows/ubuntu.yml | 3 ++ src/CMakeLists.txt | 2 +- src/cmake/common-settings.cmake | 2 +- src/ext/yuni/src/yuni/CMakeLists.txt | 2 +- .../yuni/src/yuni/core/string/operators.hxx | 12 +++--- .../src/libs/antares/study/test_study.cpp | 4 +- .../component/spotlight/listbox-panel.cpp | 5 ++- src/ui/simulator/application/main/main.cpp | 2 +- .../components/datagrid/renderer/layers.cpp | 4 +- .../windows/bindingconstraint/edit.cpp | 2 +- .../windows/correlation/datasources.hxx | 2 +- src/ui/simulator/windows/hydro/dailypower.cpp | 11 ------ src/ui/simulator/windows/hydro/management.cpp | 14 +++---- 17 files changed, 64 insertions(+), 66 deletions(-) diff --git a/.github/workflows/centos7.yml b/.github/workflows/centos7.yml index eb76c64582..85c692f581 100644 --- a/.github/workflows/centos7.yml +++ b/.github/workflows/centos7.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - branches: - - develop + - branches: + - develop schedule: - cron: '21 2 * * *' @@ -54,9 +54,14 @@ jobs: unzip -q ortools.zip rm ortools.zip + - name: Install gcc 10 + run: | + yum install -y centos-release-scl + yum install -y devtoolset-10-gcc* + - name: Configure run: | - source /opt/rh/devtoolset-9/enable + source /opt/rh/devtoolset-10/enable cmake3 -B _build -S src \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ @@ -70,7 +75,7 @@ jobs: - name: Build run: | - source /opt/rh/devtoolset-9/enable + source /opt/rh/devtoolset-10/enable source /opt/rh/rh-git227/enable cmake3 --build _build --config Release -j$(nproc) ccache -s diff --git a/.github/workflows/oracle8.yml b/.github/workflows/oracle8.yml index 3148c8c7f2..0ab2fa1530 100644 --- a/.github/workflows/oracle8.yml +++ b/.github/workflows/oracle8.yml @@ -4,8 +4,8 @@ on: release: types: [created] push: - branches: - - develop + - branches: + - develop schedule: - cron: '21 2 * * *' @@ -34,7 +34,7 @@ jobs: - name: Install libraries run: | dnf install -y epel-release git cmake wget rpm-build redhat-lsb-core - dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-9-toolchain zlib-devel + dnf install -y unzip libuuid-devel boost-test boost-devel gcc-toolset-10-toolchain zlib-devel - name: Checkout run: | @@ -51,7 +51,7 @@ jobs: - name: Configure run: | - source /opt/rh/gcc-toolset-9/enable + source /opt/rh/gcc-toolset-10/enable cmake -B _build -S src \ -DCMAKE_BUILD_TYPE=release \ -DBUILD_TESTING=ON \ @@ -60,7 +60,7 @@ jobs: - name: Build run: | - source /opt/rh/gcc-toolset-9/enable + source /opt/rh/gcc-toolset-10/enable cmake --build _build --config Release -j$(nproc) - name: Run unit and end-to-end tests diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index fb797a0805..44908b595c 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -15,7 +15,7 @@ jobs: if: "!contains(github.event.head_commit.message, '[skip ci]')" strategy: matrix: - os: [ubuntu-20.04] + os: [ ubuntu-20.04 ] env: SONAR_SERVER_URL: "https://sonarcloud.io" @@ -37,9 +37,10 @@ jobs: - name: Install libraries run: | - sudo apt-get update - sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev - sudo apt-get install libboost-test-dev + sudo apt-get update + sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev + sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Read antares-deps version id: antares-deps-version @@ -67,8 +68,8 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - pip3 install -r src/tests/examples/requirements.txt + python -m pip install --upgrade pip + pip3 install -r src/tests/examples/requirements.txt - name: Init submodule run: | @@ -77,21 +78,23 @@ jobs: - name: Configure run: | - cmake -B _build -S src \ - -DCMAKE_C_COMPILER_LAUNCHER=ccache \ - -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ - -DDEPS_INSTALL_DIR=./rte-antares-deps-Debug \ - -DCODE_COVERAGE=ON \ - -DCMAKE_BUILD_TYPE=debug \ - -DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \ - -DBUILD_TESTING=ON \ - -DMZ_CODE_COVERAGE=ON \ - -DBUILD_not_system=OFF \ - -DPython3_EXECUTABLE='${{ steps.setup-python.outputs.python-path }}' + cmake -B _build -S src \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ + -DDEPS_INSTALL_DIR=./rte-antares-deps-Debug \ + -DCODE_COVERAGE=ON \ + -DCMAKE_BUILD_TYPE=debug \ + -DCMAKE_PREFIX_PATH="../install;${{ env.ORTOOLS_DIR }}/install" \ + -DBUILD_TESTING=ON \ + -DMZ_CODE_COVERAGE=ON \ + -DBUILD_not_system=OFF \ + -DPython3_EXECUTABLE='${{ steps.setup-python.outputs.python-path }}' - name: Build run: | - build-wrapper-linux-x86-64 --out-dir $GITHUB_WORKSPACE/_build/output cmake --build _build --config release -j2 + build-wrapper-linux-x86-64 --out-dir $GITHUB_WORKSPACE/_build/output cmake --build _build --config release -j2 - name: Test and generate coverage continue-on-error: true diff --git a/.github/workflows/ubuntu-system-deps-build.yml b/.github/workflows/ubuntu-system-deps-build.yml index 34fcc2d91a..bd81673e9e 100644 --- a/.github/workflows/ubuntu-system-deps-build.yml +++ b/.github/workflows/ubuntu-system-deps-build.yml @@ -25,6 +25,7 @@ jobs: sudo apt-get update sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Set up Python uses: actions/setup-python@v4 @@ -42,7 +43,7 @@ jobs: - name: Configure run: | - cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_BUILD_TYPE=release -DBUILD_TESTING=ON + cmake -B _build -S src -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER=/usr/bin/gcc-10 -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 -DCMAKE_BUILD_TYPE=release -DBUILD_TESTING=ON - name: Build run: | diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 28c5c36b2c..15d84bc5e9 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -51,6 +51,7 @@ jobs: sudo apt-get update sudo apt-get install uuid-dev libwxgtk3.0-gtk3-dev sudo apt-get install libboost-test-dev + sudo apt-get install g++-10 gcc-10 - name: Read antares-deps version id: antares-deps-version @@ -92,7 +93,9 @@ jobs: run: | cmake -B _build -S src \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \ -DDEPS_INSTALL_DIR=${{github.workspace}}/rte-antares-deps-Release \ -DCMAKE_BUILD_TYPE=release \ -DBUILD_TESTING=ON \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 878d934250..fb3cff9705 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,7 +35,7 @@ include(CheckCXXCompilerFlag) include(CMakeDependentOption) include(FetchContent) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) if (DEFINED VCPKG_ROOT) include(${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) diff --git a/src/cmake/common-settings.cmake b/src/cmake/common-settings.cmake index 644111506c..8a3f7626fc 100644 --- a/src/cmake/common-settings.cmake +++ b/src/cmake/common-settings.cmake @@ -1,7 +1,7 @@ # # Common FLAGS for all compilers # -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(COMMON_GCC_FLAGS "-Wall -W -Wextra -Wfatal-errors") if (NOT WIN32) diff --git a/src/ext/yuni/src/yuni/CMakeLists.txt b/src/ext/yuni/src/yuni/CMakeLists.txt index 758a906e5c..5914a15a3c 100644 --- a/src/ext/yuni/src/yuni/CMakeLists.txt +++ b/src/ext/yuni/src/yuni/CMakeLists.txt @@ -31,7 +31,7 @@ include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common-settings.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules.cmake") -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) if(YUNI_MODULE_CORE) # The header yuni.h must be available diff --git a/src/ext/yuni/src/yuni/core/string/operators.hxx b/src/ext/yuni/src/yuni/core/string/operators.hxx index e7e26e52da..2ef7c24fca 100644 --- a/src/ext/yuni/src/yuni/core/string/operators.hxx +++ b/src/ext/yuni/src/yuni/core/string/operators.hxx @@ -112,39 +112,39 @@ inline Yuni::CString operator+(const Yuni::CString& rh template inline bool operator==(const char* lhs, const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const char* lhs, const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } template inline bool operator==(const char lhs[N], const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const char lhs[N], const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } template inline bool operator==(const std::basic_string& lhs, const Yuni::CString& rhs) { - return rhs == lhs; + return rhs.equals(lhs); } template inline bool operator!=(const std::basic_string& lhs, const Yuni::CString& rhs) { - return rhs != lhs; + return !rhs.equals(lhs); } inline bool operator==(const AnyString& mbs, Yuni::UTF8::Char c) diff --git a/src/tests/src/libs/antares/study/test_study.cpp b/src/tests/src/libs/antares/study/test_study.cpp index 91c8718140..8ab0d731e1 100644 --- a/src/tests/src/libs/antares/study/test_study.cpp +++ b/src/tests/src/libs/antares/study/test_study.cpp @@ -53,9 +53,9 @@ BOOST_AUTO_TEST_SUITE(areas_operations) BOOST_AUTO_TEST_CASE(area_add) { Study study; - Area* areaA = study.areaAdd("A"); + const auto areaA = study.areaAdd("A"); BOOST_CHECK(areaA != nullptr); - BOOST_CHECK(areaA->name == "A"); + BOOST_CHECK_EQUAL(areaA->name, "A"); BOOST_CHECK(areaA->id == "a"); } diff --git a/src/ui/common/component/spotlight/listbox-panel.cpp b/src/ui/common/component/spotlight/listbox-panel.cpp index 969d9672a3..9f3c8703d7 100644 --- a/src/ui/common/component/spotlight/listbox-panel.cpp +++ b/src/ui/common/component/spotlight/listbox-panel.cpp @@ -222,7 +222,8 @@ void ListboxPanel::onDraw(wxPaintEvent&) { auto& item = *(items[i]); auto& group = item.group(); - if (!(!group) && group != pLastGroupName) + + if (!(!group) && YString(group) != pLastGroupName) pLastGroupName = group; } continue; @@ -234,7 +235,7 @@ void ListboxPanel::onDraw(wxPaintEvent&) // Draw of the group name if the flag is enabled if ((0 != (pFlags & Spotlight::optGroups))) { - if (!(!group) && group != pLastGroupName) + if (!(!group) && YString(group) != pLastGroupName) { // Drawing the new group bounds.x = 0; diff --git a/src/ui/simulator/application/main/main.cpp b/src/ui/simulator/application/main/main.cpp index d4cca35472..909175937b 100644 --- a/src/ui/simulator/application/main/main.cpp +++ b/src/ui/simulator/application/main/main.cpp @@ -809,7 +809,7 @@ void ApplWnd::title(const wxString& s) wxString t; if (StudyHasBeenModified()) t << wxT("* "); - t << (s.IsEmpty() ? wxT("") : s) << wxT(" - Antares Simulator") + t << (s.IsEmpty() ? wxString(wxT("")) : s) << wxT(" - Antares Simulator") #ifndef NDEBUG << wxT(" - DEVELOPER PREVIEW") #endif diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp index e5d30d6164..2072c2cb73 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/layers.cpp @@ -227,13 +227,13 @@ wxString LayersUI::cellValue(int x, int y) const return layerPosition != layerListEnd ? wxString::Format(wxT("%d"), pArea->ui->layerX[layerIterator->first]) - : wxT("-"); + : wxString(wxT("-")); case 2: return layerPosition != layerListEnd ? wxString::Format(wxT("%d"), pArea->ui->layerY[layerIterator->first]) - : wxT("-"); + : wxString(wxT("-")); } } return wxEmptyString; diff --git a/src/ui/simulator/windows/bindingconstraint/edit.cpp b/src/ui/simulator/windows/bindingconstraint/edit.cpp index 42b1e30d84..60242c67d3 100644 --- a/src/ui/simulator/windows/bindingconstraint/edit.cpp +++ b/src/ui/simulator/windows/bindingconstraint/edit.cpp @@ -273,7 +273,7 @@ void BindingConstraintInfoEditor::onSave(void*) if (pConstraint) { - if (not newname.empty() and pConstraint->name() != newname) + if (not newname.empty() and pConstraint->name() != Data::ConstraintName(newname)) { if (not study.bindingConstraints.rename(pConstraint, newname)) { diff --git a/src/ui/simulator/windows/correlation/datasources.hxx b/src/ui/simulator/windows/correlation/datasources.hxx index aedafb6d17..07468e3dd9 100644 --- a/src/ui/simulator/windows/correlation/datasources.hxx +++ b/src/ui/simulator/windows/correlation/datasources.hxx @@ -182,7 +182,7 @@ public: { int lastLevel = 0; int j = 0; - Yuni::CString<15, false> old; + Yuni::CString<12, false> old; wxColour color; wxColour colorIdentity; const Data::Area::Vector::const_iterator end = pArray.end(); diff --git a/src/ui/simulator/windows/hydro/dailypower.cpp b/src/ui/simulator/windows/hydro/dailypower.cpp index 8a99499e05..538236c1bd 100644 --- a/src/ui/simulator/windows/hydro/dailypower.cpp +++ b/src/ui/simulator/windows/hydro/dailypower.cpp @@ -26,15 +26,12 @@ */ #include "dailypower.h" -#include #include "../../toolbox/components/datagrid/renderer/area/hydroprepro.h" #include "../../toolbox/components/datagrid/renderer/area/inflowpattern.h" #include "../../toolbox/components/datagrid/renderer/area/hydromonthlypower.h" #include "../../toolbox/components/datagrid/renderer/area/creditmodulations.h" -#include "../../toolbox/components/button.h" #include "../../toolbox/validator.h" #include "../../toolbox/create.h" -#include "../../application/menus.h" #include using namespace Yuni; @@ -73,14 +70,6 @@ void Dailypower::createComponents() wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); pSupport->SetSizer(sizer); - const wxSize ourDefaultSize(55, wxDefaultSize.GetHeight()); - - enum - { - right = wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, - left = wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, - }; - wxBoxSizer* sizerHigh = new wxBoxSizer(wxHORIZONTAL); sizer->Add(sizerHigh, 2, wxALL | wxEXPAND | wxFIXED_MINSIZE); diff --git a/src/ui/simulator/windows/hydro/management.cpp b/src/ui/simulator/windows/hydro/management.cpp index c76bfc6d05..666fd9b01d 100644 --- a/src/ui/simulator/windows/hydro/management.cpp +++ b/src/ui/simulator/windows/hydro/management.cpp @@ -26,15 +26,14 @@ */ #include "management.h" -#include +#include +#include + #include "../../toolbox/components/datagrid/renderer/area/hydroprepro.h" #include "../../toolbox/components/datagrid/renderer/area/inflowpattern.h" -#include "../../toolbox/components/datagrid/renderer/area/hydromonthlypower.h" -#include "../../toolbox/components/button.h" #include "../../toolbox/validator.h" #include "../../toolbox/create.h" #include "../../application/menus.h" -#include using namespace Yuni; @@ -69,11 +68,8 @@ void Management::createComponents() const wxSize ourDefaultSize(55, wxDefaultSize.GetHeight()); - enum - { - right = wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, - left = wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, - }; + const auto right = (wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + const auto left = (wxLEFT | wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL); auto* pGrid = new wxFlexGridSizer(6, 0, 8); sizer->Add(pGrid, 0, wxALL, 15);