vczh-libraries / GacUI

GPU Accelerated C++ User Interface, with WYSIWYG developing tools, XML supports, built-in data binding and MVVM features.
Other
2.35k stars 297 forks source link

C++: error "explicit specialization in non-namespace scope" #100

Closed jimwang118 closed 10 months ago

jimwang118 commented 1 year ago

environment

ubuntu 22.10
gcc 12.2.0

Error log: /gacgen/Import/Vlpp.h:435:34: error: explicit specialization in non-namespace scope ‘class vl::collections::Pair<K, V>’ 435 | template<> | ^ /gacgen/Import/Vlpp.h:436:95: error: template-id ‘get<0>’ in declaration of primary template 436 | typename pair_internal::TypePairElementRetriver<0, Pair<K, V>>::Type& get<0>() { return key; }

vczh commented 1 year ago

Explicit specialization may be declared in any scope where its primary template may be defined (which may be different from the scope where the primary template is defined; such as with out-of-class specialization of a member template). Explicit specialization has to appear after the non-specialized template declaration.

https://en.cppreference.com/w/cpp/language/template_specialization

I think this is valid? clang++ doesn't complain about that.

jimwang118 commented 1 year ago

Explicit specialization may be declared in any scope where its primary template may be defined (which may be different from the scope where the primary template is defined; such as with out-of-class specialization of a member template). Explicit specialization has to appear after the non-specialized template declaration.

https://en.cppreference.com/w/cpp/language/template_specialization

I think this is valid? clang++ doesn't complain about that.

Yes, clang++ will not check, but the gcc compiler will. So this error occurs only when compiling with GCC under linux.

vczh commented 1 year ago

Just get some time for this issue. Does it mean I need to move the specialization out of the class? Is this the only place of this error?

jimwang118 commented 1 year ago

You can try to specify the compiler as gcc under Linux, and then compile to see this problem.

vczh commented 10 months ago

The fix: https://github.com/vczh-libraries/Vlpp/commit/163088329896128b1bdb5eab0643a24273e0366c The release: https://github.com/vczh-libraries/Vlpp/commit/521ff0276c9efbf4240149d6cf7f643403de0eab

I have not copied the release from Vlpp to GacUI yet, but you could try if it works. I will close the bug now, feel free to reopen if it still not fix the issue.

jimwang118 commented 10 months ago

I updated it under vcpkg. I updatedvczh-libraries/Release to 1.2.7.0, updated vczh-libraries/GacUI to e4d958da1dc18de3255ab930459c4418804687d0, and then tested it under Windows. After I updated the code to the latest commit, I got the following error when compiling and testing.

Import\gacgen\Import\VlppWorkflowCompiler.cpp(12149): error C7692: 'bool vl::Ptr<vl::glr::ParsingAstBase>::operator ==(const T *) const': rewritten candidate function was excluded from overload resolution because a corresponding operator!= declared in the same scope
        with
        [
            T=vl::glr::ParsingAstBase
        ]
vczh commented 10 months ago

The error looks like you are using Visual Studio, but I didn't see this error when I compile any vcxproj in the Release repo. Could you be more specific?

By the way, 1.2.7.0 is half an year ago, you could try the latest commit in the Release repo. I have not created a new release version yet still get some bugs to fix.

jimwang118 commented 10 months ago

I try the latest commit in the Release repo, but new problems arise.

vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2911): error C2065: 'FLT_MAX': undeclared identifier
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2911): error C2131: expression did not evaluate to a constant
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2911): note: a non-constant (sub-)expression was encountered
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2912): error C2065: 'FLT_MAX': undeclared identifier
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2912): error C2131: expression did not evaluate to a constant
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2912): note: a non-constant (sub-)expression was encountered
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2918): error C2065: 'DBL_MAX': undeclared identifier
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2918): error C2131: expression did not evaluate to a constant
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2918): note: a non-constant (sub-)expression was encountered
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2919): error C2065: 'DBL_MAX': undeclared identifier
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2919): error C2131: expression did not evaluate to a constant
vlpp\src\0afbb382fa-aa8e300e24\Import\gacgen\Import\VlppReflection.h(2919): note: a non-constant (sub-)expression was encountered
vczh commented 10 months ago

You could try to use the source code from release repo directly, I don't know is there anyone still maintain the library in vcpkg, it wasn't me who create the entry.

Since you are on Windows, there is a few sln files under the tutorial project. You should be good to compile them.

vczh commented 9 months ago

New Windows sdk may have changed the content which makes VlppReflection.h not able to see <limits.h>. I made a change to address this.