System: Enable and use c++20

Enable c++20 in top level cmake. Keep c++17 for GrpcInterface, as the protoc tool does not work with c++20.
Several code adjustments to fix compiler issues.
This commit is contained in:
Magne Sjaastad
2023-01-19 08:20:07 +01:00
parent 712bad97bd
commit abc9e82ff5
17 changed files with 40 additions and 20 deletions

View File

@@ -187,9 +187,19 @@ std::vector<std::string> RiaStdStringTools::splitString( const std::string& s, c
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
std::string RiaStdStringTools::joinStrings( const std::vector<std::string>& s, char delimiter ) std::string RiaStdStringTools::joinStrings( const std::vector<std::string>& s, char delimiter )
{ {
std::string delimiterString( 1, delimiter ); std::string joinedString;
return join( s.begin(), s.end(), delimiterString ); for ( const auto& str : s )
{
if ( !joinedString.empty() )
{
joinedString += delimiter;
}
joinedString += str;
}
return joinedString;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@@ -362,6 +362,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
-Wno-braced-scalar-init -Wno-braced-scalar-init
-Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-out-of-range-compare
-Wno-undefined-var-template -Wno-undefined-var-template
-Wno-ambiguous-reversed-operator
) )
endif() endif()

View File

@@ -89,6 +89,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
-Wno-braced-scalar-init -Wno-braced-scalar-init
-Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-out-of-range-compare
-Wno-undefined-var-template -Wno-undefined-var-template
-Wno-ambiguous-reversed-operator
) )
endif() endif()

View File

@@ -79,7 +79,7 @@ void RicCreatePlotFromTemplateByShortcutFeature::setupActionLook( QAction* actio
actionToSetup->setText( "Create Plot from Last Used Template" ); actionToSetup->setText( "Create Plot from Last Used Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
QKeySequence keySeq( Qt::CTRL + Qt::Key_T ); QKeySequence keySeq( Qt::CTRL, Qt::Key_T );
applyShortcutWithHintToAction( actionToSetup, keySeq ); applyShortcutWithHintToAction( actionToSetup, keySeq );
} }

View File

@@ -17,6 +17,10 @@
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// These includes need to be first to avoid compile errors when compiling with MSVC using c++20
#include <algorithm>
#include <ostream>
#ifdef _MSC_VER #ifdef _MSC_VER
// Get rid of warnings from compilation of ODB API // Get rid of warnings from compilation of ODB API
#pragma warning( push ) #pragma warning( push )
@@ -38,7 +42,9 @@
#include "RigFemTypes.h" #include "RigFemTypes.h"
#include "cafProgressInfo.h" #include "cafProgressInfo.h"
#include <QString> #include <QString>
#include <iostream> #include <iostream>
#include <limits> #include <limits>
#include <map> #include <map>

View File

@@ -244,7 +244,7 @@ QString RimWellRftPlot::associatedSimWellName() const
void RimWellRftPlot::applyInitialSelections() void RimWellRftPlot::applyInitialSelections()
{ {
std::map<QString, QStringList> wellSources = findWellSources(); std::map<QString, QStringList> wellSources = findWellSources();
if ( m_wellPathNameOrSimWellName == "None" && !wellSources.empty() ) if ( m_wellPathNameOrSimWellName() == "None" && !wellSources.empty() )
{ {
m_wellPathNameOrSimWellName = wellSources.begin()->first; m_wellPathNameOrSimWellName = wellSources.begin()->first;
} }

View File

@@ -553,7 +553,7 @@ QString RimGeoMechResultDefinition::composeFieldCompString( const QString& resul
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimGeoMechResultDefinition::initAfterRead() void RimGeoMechResultDefinition::initAfterRead()
{ {
if ( m_resultComponentName == "STM" || m_resultComponentName == "SEM" ) m_resultComponentName = "SM"; if ( m_resultComponentName() == "STM" || m_resultComponentName() == "SEM" ) m_resultComponentName = "SM";
m_resultPositionTypeUiField = m_resultPositionType; m_resultPositionTypeUiField = m_resultPositionType;
m_resultVariableUiField = composeFieldCompString( m_resultFieldName(), m_resultComponentName() ); m_resultVariableUiField = composeFieldCompString( m_resultFieldName(), m_resultComponentName() );

View File

@@ -519,7 +519,7 @@ bool RimCellEdgeColors::showTextResult() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimCellEdgeColors::updateIgnoredScalarValue() void RimCellEdgeColors::updateIgnoredScalarValue()
{ {
if ( m_resultVariable == "MULT" || m_resultVariable == "riMULT" ) if ( m_resultVariable() == "MULT" || m_resultVariable() == "riMULT" )
{ {
m_ignoredResultScalar = 1.0; m_ignoredResultScalar = 1.0;
} }

View File

@@ -193,7 +193,7 @@ void RimEclipseCellColors::initAfterRead()
{ {
RimEclipseResultDefinition::initAfterRead(); RimEclipseResultDefinition::initAfterRead();
if ( this->m_legendConfigPtrField() && this->m_legendConfigPtrField()->resultVariableName == "" ) if ( this->m_legendConfigPtrField() && this->m_legendConfigPtrField()->resultVariableName() == "" )
{ {
this->m_legendConfigPtrField()->resultVariableName = this->resultVariable(); this->m_legendConfigPtrField()->resultVariableName = this->resultVariable();
} }

View File

@@ -1277,12 +1277,12 @@ void RimEclipseResultDefinition::initAfterRead()
assignFlowSolutionFromCase(); assignFlowSolutionFromCase();
} }
if ( m_resultVariable == "Formation Allen" ) if ( m_resultVariable() == "Formation Allen" )
{ {
m_resultVariable = RiaResultNames::formationAllanResultName(); m_resultVariable = RiaResultNames::formationAllanResultName();
m_resultType = RiaDefines::ResultCatType::ALLAN_DIAGRAMS; m_resultType = RiaDefines::ResultCatType::ALLAN_DIAGRAMS;
} }
else if ( m_resultVariable == "Binary Formation Allen" ) else if ( m_resultVariable() == "Binary Formation Allen" )
{ {
m_resultVariable = RiaResultNames::formationBinaryAllanResultName(); m_resultVariable = RiaResultNames::formationBinaryAllanResultName();
m_resultType = RiaDefines::ResultCatType::ALLAN_DIAGRAMS; m_resultType = RiaDefines::ResultCatType::ALLAN_DIAGRAMS;

View File

@@ -653,11 +653,11 @@ void RimRegularLegendConfig::setAutomaticRanges( double globalMin, double global
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::initAfterRead() void RimRegularLegendConfig::initAfterRead()
{ {
if ( resultVariableName == "Binary Formation Allen" ) if ( resultVariableName() == "Binary Formation Allen" )
{ {
resultVariableName = RiaResultNames::formationBinaryAllanResultName(); resultVariableName = RiaResultNames::formationBinaryAllanResultName();
} }
else if ( resultVariableName == "Formation Allen" ) else if ( resultVariableName() == "Formation Allen" )
{ {
resultVariableName = RiaResultNames::formationAllanResultName(); resultVariableName = RiaResultNames::formationAllanResultName();
} }

View File

@@ -72,7 +72,7 @@ void RimSummaryCaseCollection::sortByBinnedVariation( std::vector<RigEnsemblePar
return; return;
} }
double delta = ( maxStdDev - minStdDev ) / RigEnsembleParameter::NR_OF_VARIATION_BINS; double delta = ( maxStdDev - minStdDev ) / (float)( RigEnsembleParameter::NR_OF_VARIATION_BINS );
std::vector<double> bins; std::vector<double> bins;
bins.push_back( 0.0 ); bins.push_back( 0.0 );

View File

@@ -111,9 +111,9 @@ void RimFileWellPath::setWellPathIndexInFile( int index )
void RimFileWellPath::setSurveyType( QString surveyType ) void RimFileWellPath::setSurveyType( QString surveyType )
{ {
m_surveyType = surveyType; m_surveyType = surveyType;
if ( m_surveyType == "PLAN" ) if ( m_surveyType() == "PLAN" )
setWellPathColor( cvf::Color3f( 0.999f, 0.333f, 0.0f ) ); setWellPathColor( cvf::Color3f( 0.999f, 0.333f, 0.0f ) );
else if ( m_surveyType == "PROTOTYPE" ) else if ( m_surveyType() == "PROTOTYPE" )
setWellPathColor( cvf::Color3f( 0.0f, 0.333f, 0.999f ) ); setWellPathColor( cvf::Color3f( 0.0f, 0.333f, 0.999f ) );
} }

View File

@@ -40,8 +40,7 @@ if(VCPKG_AUTO_INSTALL)
set(AUTO_VCPKG_ROOT "${CMAKE_SOURCE_DIR}/ThirdParty/vcpkg") set(AUTO_VCPKG_ROOT "${CMAKE_SOURCE_DIR}/ThirdParty/vcpkg")
endif() endif()
# Use CMake to enforce C++17 set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

View File

@@ -526,7 +526,7 @@ TEST( BaseTest, PdmPtrField )
// Operator -> // Operator ->
ihd1->m_ptrField->m_texts = "Hei PtrField"; ihd1->m_ptrField->m_texts = "Hei PtrField";
EXPECT_TRUE( ihd1->m_ptrField->m_texts == "Hei PtrField" ); EXPECT_TRUE( ihd1->m_ptrField->m_texts() == "Hei PtrField" );
// Referencing system // Referencing system
{ {

View File

@@ -840,12 +840,12 @@ TEST( BaseTest, PdmObjectGroupCopyOfTypedObjects )
std::vector<caf::PdmPointer<SimpleObj>> simpleObjList; std::vector<caf::PdmPointer<SimpleObj>> simpleObjList;
og.createCopyByType( &simpleObjList, caf::PdmDefaultObjectFactory::instance() ); og.createCopyByType( &simpleObjList, caf::PdmDefaultObjectFactory::instance() );
EXPECT_EQ( size_t( 3 ), simpleObjList.size() ); EXPECT_EQ( size_t( 3 ), simpleObjList.size() );
EXPECT_EQ( 1000, simpleObjList[0]->m_position ); EXPECT_EQ( 1000, simpleObjList[0]->m_position() );
EXPECT_EQ( size_t( 1 ), simpleObjList[0]->m_numbers.v().size() ); EXPECT_EQ( size_t( 1 ), simpleObjList[0]->m_numbers.v().size() );
EXPECT_EQ( 10, simpleObjList[0]->m_numbers.v()[0] ); EXPECT_EQ( 10, simpleObjList[0]->m_numbers.v()[0] );
EXPECT_EQ( 2000, simpleObjList[1]->m_position ); EXPECT_EQ( 2000, simpleObjList[1]->m_position() );
EXPECT_EQ( 3000, simpleObjList[2]->m_position ); EXPECT_EQ( 3000, simpleObjList[2]->m_position() );
std::vector<caf::PdmPointer<InheritedDemoObj>> inheritObjList; std::vector<caf::PdmPointer<InheritedDemoObj>> inheritObjList;
og.createCopyByType( &inheritObjList, caf::PdmDefaultObjectFactory::instance() ); og.createCopyByType( &inheritObjList, caf::PdmDefaultObjectFactory::instance() );

View File

@@ -21,6 +21,9 @@ if(MSVC)
add_definitions(-D_WIN32_WINNT=0x600) add_definitions(-D_WIN32_WINNT=0x600)
endif() endif()
set(CMAKE_CXX_STANDARD 17)
add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) add_definitions(-D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
find_package( find_package(