-
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 ?
-
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 ?
-
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 ?
@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)
-
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 ?
@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()
-
K kshegunov moved this topic from General and Desktop on
-
@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()
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 functionsStrange 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] -
A Andy314 has marked this topic as solved on
-
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 functionsStrange 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]@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 functionsYes, 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.
-
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 functionsStrange 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]@Andy314 said:
Strange it comes with the new Qt-version
QMAKE_CXXFLAGS += -permissiveQt6 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 implypermissive-
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.