MantisBT
Mantis Bug Tracker Workflow

View Revisions: Issue #30344 All Revisions ] Back to Issue ]
Summary 0030344: Coding Rules - suppress GCC compiler warnings -Wstrict-overflow on Standard_OutOfRange_Raise_if
Revision 2019-06-07 09:28 by kgv
Steps To Reproduce
#include <iostream>
#include <cstdlib>
#include <stdexcept>

#if defined(fff) && (defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && 
__GNUC_MINOR__ >= 6))
  #define Standard_OutOfRange_Always_Raise_if(CONDITION, MESSAGE) \
  _Pragma("GCC diagnostic push") \
  _Pragma("GCC diagnostic ignored \"-Wstrict-overflow\"") \
  if (CONDITION) throw std::out_of_range(MESSAGE); \
  _Pragma("GCC diagnostic pop")
#else
  #define Standard_OutOfRange_Always_Raise_if(CONDITION, MESSAGE) \
  if (CONDITION) throw std::out_of_range(MESSAGE);
#endif

#if !defined No_Exception && !defined No_Standard_OutOfRange
  #define Standard_OutOfRange_Raise_if(CONDITION, MESSAGE) Standard_OutOfRange_Always_Raise_if(CONDITION, 
MESSAGE)
#else
  #define Standard_OutOfRange_Raise_if(CONDITION, MESSAGE)
#endif

class MyArray
{
public:
  MyArray (int theLength) : myArray (new double[theLength]), myLength (theLength) {}
  ~MyArray() { delete[] myArray; }

  int Length() const { return myLength; }

  void SetValue (int theIndex, double theValue);
private:
  double* myArray;
  int myLength;
};

inline void MyArray::SetValue (int theIndex, double theValue)
{
  //int aDummy;
  Standard_OutOfRange_Always_Raise_if(theIndex < 0 || theIndex > myLength, "Out of Range");
  
myArray[theIndex - 1] = theValue;
}


void MyFunction (MyArray& theArray)
{
  theArray.SetValue (theArray.Length() - 1, 10.0);
}

int main()
{
  MyArray anArray (10);
  MyFunction (anArray);
  return 0;
}


> g++ test.cxx -Wall -Wextra -O2 -std=gnu++11 -fexceptions
Revision 2018-11-06 15:48 by kgv
Steps To Reproduce


Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker