Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved remove -fpermissive warning

    General and Desktop
    gcc
    3
    5
    9928
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Andy314
      Andy314 last edited by Andy314

      Sorry this question hast not really to do with Qt but maybe someone knows the answer.
      I switched from MSVC to MinGW and learned something about the "real" C++ standard.
      It seem if I subclass from an template-class all members of it are not in the scope for the derived class. I had never used before a compiler with such a behavior.

      template <typename T> class Base
      {public:
        int foovar;
        int foo();
      }
      template <typename T> class Derived: public Base<T>
      { 
           void Test1()   {   int k=foovar;  foo(); }   // compiler error 
           void Test2()   {   int k=this->foovar;  this->foo(); }   // ok
      }
      

      The thousands of this-> I must insert in my code now are very annoying and I dont like the long code.
      With the -fpermissive flag I can avoid the errors for memberfunctions (not for member varianbles :-( ) but I get warnings for it.
      Now I am looking for a way to supress these warings. I found
      #pragma GCC diagnostic ignored "-fpermissive"
      but this never works.
      Has someone a solution for it ?

      kshegunov 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Out of curiosity, what's the use of k ?

        Also, what exact error message are you getting ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • kshegunov
          kshegunov Moderators @Andy314 last edited by kshegunov

          @Andy314

          So you want to basically ignore warnings like "Taking an address of a temporary variable" and the such? Not a very wise decision to disable compiler warnings, especially this particular one.

          It seem if I subclass from an template-class all members of it are not in the scope for the derived class.

          Because the base class is dependent on a template parameter.

          I had never used before a compiler with such a behavior.

          If you come from the MS world, that's somewhat expected, since the MS compiler is not very standards compliant (similarly to most if not all of their other products).

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply Reply Quote 0
          • Andy314
            Andy314 last edited by Andy314

            Sorry for my unclear explanation. I get this error for example:

            C:\Projects\Source\Qt\CarDamage\CDLookups.h:288: error: there are no arguments to 'count' that depend on a template parameter, so a declaration of 'count' must be available [-fpermissive]
            for(int i=0; i<count(); i++)
            ^
            In "normal" subclassing without templates there is a simple lookup -mechanism to find identifier in a funktion of the derived class: Search in the base class , if not found search in the global namespace.
            With a template-base-class this does not work in GCC. The logic is, look only in the global namespace.
            I must tell the compiler explicte that a template member should be used. I can do this with:
            Base<T>::foovar , Base<T>::foo() or
            this->foovar; this->foo();
            This blows up my code at thousands of lines very much and I dont like it.
            To avaid this error for memberfunctions I can integrate a compiler switch -fpermissive but I get the warnings for it.

            kshegunov 1 Reply Last reply Reply Quote 0
            • kshegunov
              kshegunov Moderators @Andy314 last edited by kshegunov

              @Andy314

              In "normal" subclassing without templates there is a simple lookup -mechanism to find identifier in a funktion of the derived class: Search in the base class , if not found search in the global namespace.

              In "normal subclassing" the class is known, while with templates the class is generated by the compiler when instantiation is performed. If you don't make a specialization of the template, no code will be ever generated for the template. So when reading the template the compiler is "confused" how to deduce which count() exactly you mean. Granted, most of the time it's the base class/derived class' implementation, but this gets really complicated really fast when the overloading rules should be applied. That's why it's whining (mostly harmlessly) that you "should" specify which function exactly you mean (as required by the C++ standard).

              This blows up my code at thousands of lines very much and I dont like it. To avaid this error for memberfunctions I can integrate a compiler switch -fpermissive but I get the warnings for it.

              Templates are pretty verbose, I sympathize, but switching off compiler warnings/errors is not a good solution. As I mentioned, -fpermissive includes very many warnings/errors, most of which are quite important and you'd get much more headaches by switching it off, than by explicitly specifying which functions you want called. If you still insist on using the flag, you can set it in the project file through the QMAKE_CXXFLAGS variable:

              QMAKE_CXXFLAGS += -fpermissive
              

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply Reply Quote 1
              • First post
                Last post