Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. C++-Compiler error by switching to new Qt-Version
QtWS25 Last Chance

C++-Compiler error by switching to new Qt-Version

Scheduled Pinned Locked Moved Solved C++ Gurus
7 Posts 5 Posters 1.2k Views
  • 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    The problem is probably not directly related to qt, nevertheless it comes with the update from Qt 5.15.1 to Qt 6.4.2.
    For both configuration I use the same compiler MSVC2019 64 bit on the same computer !

    template <class Type>
    class base1
    {public:
        void test1();
    };
    
    template <class Type>
    class base2: public base1<Type>
    {public:
        void test4() { base1<Type>::test1(); }  // ok
        void test3() { this->test1(); }         // ok
        void test2() { test1(); }               // test1 not found, new error for me
    };
    

    test2() worked for the old Qt-Version. I never needed the explicit naming of the base class or must use the this->.
    The error occures only for templates. "Normal" classes work.

    Can it be that the new Qt version changes a compiler setting of the MSVC ?

    tomyT D kshegunovK 3 Replies Last reply
    0
    • Andy314A Andy314

      The problem is probably not directly related to qt, nevertheless it comes with the update from Qt 5.15.1 to Qt 6.4.2.
      For both configuration I use the same compiler MSVC2019 64 bit on the same computer !

      template <class Type>
      class base1
      {public:
          void test1();
      };
      
      template <class Type>
      class base2: public base1<Type>
      {public:
          void test4() { base1<Type>::test1(); }  // ok
          void test3() { this->test1(); }         // ok
          void test2() { test1(); }               // test1 not found, new error for me
      };
      

      test2() worked for the old Qt-Version. I never needed the explicit naming of the base class or must use the this->.
      The error occures only for templates. "Normal" classes work.

      Can it be that the new Qt version changes a compiler setting of the MSVC ?

      tomyT Offline
      tomyT Offline
      tomy
      wrote on last edited by
      #2

      @Andy314
      The error is quite explanatory: there are no arguments to 'test1' that depend on a template parameter, so a declaration of 'test1' must be available.

      1 Reply Last reply
      0
      • Andy314A Andy314

        The problem is probably not directly related to qt, nevertheless it comes with the update from Qt 5.15.1 to Qt 6.4.2.
        For both configuration I use the same compiler MSVC2019 64 bit on the same computer !

        template <class Type>
        class base1
        {public:
            void test1();
        };
        
        template <class Type>
        class base2: public base1<Type>
        {public:
            void test4() { base1<Type>::test1(); }  // ok
            void test3() { this->test1(); }         // ok
            void test2() { test1(); }               // test1 not found, new error for me
        };
        

        test2() worked for the old Qt-Version. I never needed the explicit naming of the base class or must use the this->.
        The error occures only for templates. "Normal" classes work.

        Can it be that the new Qt version changes a compiler setting of the MSVC ?

        D Offline
        D Offline
        DerReisende
        wrote on last edited by
        #3

        @Andy314 This is what gcc will give as an error:

        In member function 'void base2<Type>::test2()':
        error: there are no arguments to 'test1' that depend on a template parameter, so a declaration of 'test1' must be available [-fpermissive]
           12 |     void test2() { test1(); }               // test1 not found, new error for me
              |                    ^~~~~
        <source>:12:20: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
        
        1 Reply Last reply
        0
        • Andy314A Andy314

          The problem is probably not directly related to qt, nevertheless it comes with the update from Qt 5.15.1 to Qt 6.4.2.
          For both configuration I use the same compiler MSVC2019 64 bit on the same computer !

          template <class Type>
          class base1
          {public:
              void test1();
          };
          
          template <class Type>
          class base2: public base1<Type>
          {public:
              void test4() { base1<Type>::test1(); }  // ok
              void test3() { this->test1(); }         // ok
              void test2() { test1(); }               // test1 not found, new error for me
          };
          

          test2() worked for the old Qt-Version. I never needed the explicit naming of the base class or must use the this->.
          The error occures only for templates. "Normal" classes work.

          Can it be that the new Qt version changes a compiler setting of the MSVC ?

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @Andy314 said in C++-Compiler error by switching to new Qt-Version:

          I never needed the explicit naming of the base class or must use the this->.

          Then you were not using a conformant implementation.

          The error occures only for templates. "Normal" classes work.

          Because that error only makes sense for templates. So this is normal.

          Can it be that the new Qt version changes a compiler setting of the MSVC ?

          Probably expands to a newer version of the compiler/stdlib, but I don't believe Qt has anything to do with it. Check the compiler flags you pass on for the two builds (incl. the build system). But in any case you should fix your code. Either you want:

          using base1<Type>::test1;
          

          or simply what most people do: this->test1()

          Read and abide by the Qt Code of Conduct

          Andy314A 1 Reply Last reply
          1
          • kshegunovK kshegunov moved this topic from General and Desktop on
          • kshegunovK kshegunov

            @Andy314 said in C++-Compiler error by switching to new Qt-Version:

            I never needed the explicit naming of the base class or must use the this->.

            Then you were not using a conformant implementation.

            The error occures only for templates. "Normal" classes work.

            Because that error only makes sense for templates. So this is normal.

            Can it be that the new Qt version changes a compiler setting of the MSVC ?

            Probably expands to a newer version of the compiler/stdlib, but I don't believe Qt has anything to do with it. Check the compiler flags you pass on for the two builds (incl. the build system). But in any case you should fix your code. Either you want:

            using base1<Type>::test1;
            

            or simply what most people do: this->test1()

            Andy314A Offline
            Andy314A Offline
            Andy314
            wrote on last edited by
            #5

            Hello @kshegunov,

            the this-> methode seem the best solution.

            Its a little bit ugly for me and contradictionary to the normal scope lookup problem in C++.
            derived class -> base class(es) (if no normal function found, take curr. Templ.Par) -> global functions

            Strange it comes with the new Qt-version
            QMAKE_CXXFLAGS += -permissive
            should avoid the error, but this switch is no more allowed because of a static_assert in qgloabal.h.

            I will share some information I found:
            [https://kernhanda.github.io/templates-inheritance-methods/])
            [https://developercommunity.visualstudio.com/t/confusing-error-message-when-a-templated-derived-c/1048624]

            kshegunovK Chris KawaC 2 Replies Last reply
            0
            • Andy314A Andy314 has marked this topic as solved on
            • Andy314A Andy314

              Hello @kshegunov,

              the this-> methode seem the best solution.

              Its a little bit ugly for me and contradictionary to the normal scope lookup problem in C++.
              derived class -> base class(es) (if no normal function found, take curr. Templ.Par) -> global functions

              Strange it comes with the new Qt-version
              QMAKE_CXXFLAGS += -permissive
              should avoid the error, but this switch is no more allowed because of a static_assert in qgloabal.h.

              I will share some information I found:
              [https://kernhanda.github.io/templates-inheritance-methods/])
              [https://developercommunity.visualstudio.com/t/confusing-error-message-when-a-templated-derived-c/1048624]

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @Andy314 said in C++-Compiler error by switching to new Qt-Version:

              Its a little bit ugly for me and contradictionary to the normal scope lookup problem in C++.
              derived class -> base class(es) (if no normal function found, take curr. Templ.Par) -> global functions

              Yes, but template dependent name lookup is a bit more demanding, so it is necessary. This actually facilitates the following valid code:

              template <typename Implementation>
              class A : public Implementation
              {
                  void foo()
                  {
                        this->bar(); // Where Implementation provides bar()
                  }
              };
              

              QMAKE_CXXFLAGS += -permissive
              should avoid the error, but this switch is no more allowed because of a static_assert in qgloabal.h.

              You should never use that flag. This basically allows non-conformant code to compile (i.e. code that has UBs in it), so forget it exists.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1
              • Andy314A Andy314

                Hello @kshegunov,

                the this-> methode seem the best solution.

                Its a little bit ugly for me and contradictionary to the normal scope lookup problem in C++.
                derived class -> base class(es) (if no normal function found, take curr. Templ.Par) -> global functions

                Strange it comes with the new Qt-version
                QMAKE_CXXFLAGS += -permissive
                should avoid the error, but this switch is no more allowed because of a static_assert in qgloabal.h.

                I will share some information I found:
                [https://kernhanda.github.io/templates-inheritance-methods/])
                [https://developercommunity.visualstudio.com/t/confusing-error-message-when-a-templated-derived-c/1048624]

                Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #7

                @Andy314 said:

                Strange it comes with the new Qt-version
                QMAKE_CXXFLAGS += -permissive

                Qt6 requires C++17 and requires permissive- switch in MSVC (not to confuse with -permissive, which is the same as /permissive). Further C++ standards in MSVC imply permissive- and are required for some of the new features like modules or concepts. Qt6 requires it to avoid having to support non-standard code paths for a single supported compiler.

                permissive- switch turns off all language extensions and makes the implementation conformant with the standard.

                As @kshegunov said, you should not be using permissive. It locks you into MSVC specific toolchain and will make updates to future standards harder and error prone.
                I'd say keep the standard conformance on and fix code that is nonstandard.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved