From f49de5c4cf157b5e11163e2358d50ded0ec09940 Mon Sep 17 00:00:00 2001 From: Andre Sailer <andre.philippe.sailer@cern.ch> Date: Tue, 20 Aug 2019 10:36:49 +0200 Subject: [PATCH] Make fallthrough attribute ignored in c++14 --- DDCore/src/FieldTypes.cpp | 19 ++++++++++++++---- DDCore/src/XML/tinyxmlparser_inl.h | 20 +++++++++++++++---- DDG4/plugins/Geant4EventSeed.h | 32 ++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/DDCore/src/FieldTypes.cpp b/DDCore/src/FieldTypes.cpp index c4715fb00..eb2c5b099 100644 --- a/DDCore/src/FieldTypes.cpp +++ b/DDCore/src/FieldTypes.cpp @@ -22,6 +22,17 @@ using namespace dd4hep; #define INFINITY (numeric_limits<double>::max()) #endif +// fallthrough only exists from c++17 +#if defined __has_cpp_attribute + #if __has_cpp_attribute(fallthrough) + #define ATTR_FALLTHROUGH [[fallthrough]] + #else + #define ATTR_FALLTHROUGH + #endif +#else + #define ATTR_FALLTHROUGH +#endif + DD4HEP_INSTANTIATE_HANDLE(ConstantField); DD4HEP_INSTANTIATE_HANDLE(SolenoidField); DD4HEP_INSTANTIATE_HANDLE(DipoleField); @@ -101,19 +112,19 @@ void MultipoleField::fieldComponents(const double* pos, double* field) { case 4: // Ocupole momentum by += (1./6.) * ( coefficents[3] * (x2*x - 3.0*x*y2) + skews[3]*(y2*y - 3.0*x2*y) ); bx += (1./6.) * ( coefficents[3] * (3.0*x2*y - y2*y) + skews[3]*(x2*x - 3.0*x*y2) ); - [[fallthrough]]; + ATTR_FALLTHROUGH; case 3: // Sextupole momentum: by += (1./2.) * ( coefficents[2] * (x2 - y2) - skews[2] * 2.0 * xy ); bx += (1./2.) * ( coefficents[2] * 2.0 * xy + skews[2] * (x2 - y2) ); - [[fallthrough]]; + ATTR_FALLTHROUGH; case 2: // Quadrupole momentum: bx += coefficents[1] * y + skews[1]*x; by += coefficents[1] * x - skews[1]*y; - [[fallthrough]]; + ATTR_FALLTHROUGH; case 1: // Dipole momentum: bx += skews[0]; by += coefficents[0]; - [[fallthrough]]; + ATTR_FALLTHROUGH; case 0: // Nothing, but still valid break; default: // Error condition diff --git a/DDCore/src/XML/tinyxmlparser_inl.h b/DDCore/src/XML/tinyxmlparser_inl.h index b9284f720..0db63967f 100644 --- a/DDCore/src/XML/tinyxmlparser_inl.h +++ b/DDCore/src/XML/tinyxmlparser_inl.h @@ -41,6 +41,18 @@ # endif #endif +// fallthrough only exists from c++17 +#if defined __has_cpp_attribute + #if __has_cpp_attribute(fallthrough) + #define ATTR_FALLTHROUGH [[fallthrough]] + #else + #define ATTR_FALLTHROUGH + #endif +#else + #define ATTR_FALLTHROUGH +#endif + + // Note tha "PutString" hardcodes the same list. This // is less flexible than it appears. Changing the entries // or order will break putstring. @@ -119,21 +131,21 @@ void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* leng --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; - [[fallthrough]]; + ATTR_FALLTHROUGH; case 3: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; - [[fallthrough]]; + ATTR_FALLTHROUGH; case 2: --output; *output = (char)((input | BYTE_MARK) & BYTE_MASK); input >>= 6; - [[fallthrough]]; + ATTR_FALLTHROUGH; case 1: --output; *output = (char)(input | FIRST_BYTE_MARK[*length]); - [[fallthrough]]; + ATTR_FALLTHROUGH; default: break; } diff --git a/DDG4/plugins/Geant4EventSeed.h b/DDG4/plugins/Geant4EventSeed.h index 67dab26da..e192a4750 100644 --- a/DDG4/plugins/Geant4EventSeed.h +++ b/DDG4/plugins/Geant4EventSeed.h @@ -16,6 +16,18 @@ // Framework include files #include "DDG4/Geant4RunAction.h" +// fallthrough only exists from c++17 +#if defined __has_cpp_attribute + #if __has_cpp_attribute(fallthrough) + #define ATTR_FALLTHROUGH [[fallthrough]] + #else + #define ATTR_FALLTHROUGH + #endif +#else + #define ATTR_FALLTHROUGH +#endif + + /// Namespace for the AIDA detector description toolkit namespace dd4hep { @@ -166,17 +178,17 @@ namespace dd4hep { c += length; switch ( len ) { - case 11: c += ( (unsigned)k[10] << 24 ); [[fallthrough]]; - case 10: c += ( (unsigned)k[9] << 16 ); [[fallthrough]]; - case 9 : c += ( (unsigned)k[8] << 8 ); [[fallthrough]]; + case 11: c += ( (unsigned)k[10] << 24 ); ATTR_FALLTHROUGH; + case 10: c += ( (unsigned)k[9] << 16 ); ATTR_FALLTHROUGH; + case 9 : c += ( (unsigned)k[8] << 8 ); ATTR_FALLTHROUGH; /* First byte of c reserved for length */ - case 8 : b += ( (unsigned)k[7] << 24 ); [[fallthrough]]; - case 7 : b += ( (unsigned)k[6] << 16 ); [[fallthrough]]; - case 6 : b += ( (unsigned)k[5] << 8 ); [[fallthrough]]; - case 5 : b += k[4]; [[fallthrough]]; - case 4 : a += ( (unsigned)k[3] << 24 ); [[fallthrough]]; - case 3 : a += ( (unsigned)k[2] << 16 ); [[fallthrough]]; - case 2 : a += ( (unsigned)k[1] << 8 ); [[fallthrough]]; + case 8 : b += ( (unsigned)k[7] << 24 ); ATTR_FALLTHROUGH; + case 7 : b += ( (unsigned)k[6] << 16 ); ATTR_FALLTHROUGH; + case 6 : b += ( (unsigned)k[5] << 8 ); ATTR_FALLTHROUGH; + case 5 : b += k[4]; ATTR_FALLTHROUGH; + case 4 : a += ( (unsigned)k[3] << 24 ); ATTR_FALLTHROUGH; + case 3 : a += ( (unsigned)k[2] << 16 ); ATTR_FALLTHROUGH; + case 2 : a += ( (unsigned)k[1] << 8 ); ATTR_FALLTHROUGH; case 1 : a += k[0]; } -- GitLab