Always turn on "-fpermissive" for GCC 4.6

  |   Source

turn on "-fpermissive" for GCC 4.6 :linux:gcc:en:cmake:

Below code will get error message if compiled by gcc 4.6+:

"const A" as 'this' argument of "void A::a()' discards qualifiers [-fpermissive]
class A
{
   void a();
}
class B
{
   virtual void b() const;
}
class MyClass:public B
{
  A _a;
  virtual b() const
  {
    _a.a(); //gcc complains here!
  }
}

Since I cannot modify class A and B, I need add "-fpermission" to CXX_FLAG. Here is my cmake code,

if(CMAKE_COMPILER_IS_GNUCC)
  # needed for gcc 4.6+
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
endif()
Comments powered by Disqus