Page 1 of 1

Clang compile issues with unused variable in ReflectionImplement.h

Posted: 26 Mar 2024, 12:03
by HateDread
For NS_IMPLEMENT_REFLECTION2, 'helper' is not used, fix is adding '[[maybe_unused]]':

NS_COLD_FUNC void classType::StaticFillClassType([[maybe_unused]] Noesis::TypeClassCreator& helper)

Same with NS_IMPLEMENT_INLINE_REFLECTION3:

NS_COLD_FUNC static void StaticFillClassType([[maybe_unused]] Noesis::TypeClassCreator& helper)

Thanks!

Re: Clang compile issues with unused variable in ReflectionImplement.h

Posted: 26 Mar 2024, 13:09
by HateDread
Also getting an issue in non-debug Clang build

15>C:\_Development\Repositories\rtg\libs\NoesisUtils\Private\App.Providers.cpp(13,1): error : unexpected argument 's' to '#pragma optimize'; expected "" [-Werror,-Wignored-pragmas]
15>C:\_Development\Repositories\rtg\third_party\Noesis\Include\NsCore\CompilerSettings.h(64,47): note: expanded from macro 'NS_BEGIN_COLD_REGION'
15>C:\_Development\Repositories\rtg\libs\NoesisUtils\Private\Behavior.cpp(38,1): error : unexpected argument 's' to '#pragma optimize'; expected "" [-Werror,-Wignored-pragmas]
15>C:\_Development\Repositories\rtg\third_party\Noesis\Include\NsCore\CompilerSettings.h(64,47): note: expanded from macro 'NS_BEGIN_COLD_REGION'

Temp fix:
    #if defined(_DEBUG) || __clang__
        #define NS_BEGIN_COLD_REGION
        #define NS_END_COLD_REGION
    #else
        #define NS_BEGIN_COLD_REGION __pragma(optimize("s", on))
        #define NS_END_COLD_REGION __pragma(optimize("", on))
    #endif
Another:

2>C:\_Development\Repositories\rtg\libs\NoesisUtils\Private\LocExtension.cpp(125,22): error : inequality comparison result unused [-Werror,-Wunused-comparison]
2>C:\_Development\Repositories\rtg\third_party\Noesis\Include\NsCore\Error.h(65,41): note: expanded from macro 'NS_CHECK'
2>C:\_Development\Repositories\rtg\third_party\Noesis\Include\NsCore\CompilerSettings.h(58,60): note: expanded from macro 'NS_UNUSED'
2>C:\_Development\Repositories\rtg\libs\NoesisUtils\Private\LocExtension.cpp(125,22): note: use '|=' to turn this inequality comparison into an or-assignment

Re: Clang compile issues with unused variable in ReflectionImplement.h

Posted: 26 Mar 2024, 13:36
by HateDread
Okay, I think I know what's going on here. I'm using Visual Studio and Clang together, i.e. I generate my CMake solution for Visual Studio using the following:
cmake .. -G "Visual Studio 17 2022" -T "ClangCL"
This means that when compiling, the following two statements are true
#if defined(_MSC_VER) && _MSC_VER >= 1400
#if __clang__
So it might be worth trying that build path, as it ships with VS and uses the Microsoft-provided clang-cl (if you tick the right installer option), thus some of the code in e.g. CompilerSettings.h has issues.

Re: Clang compile issues with unused variable in ReflectionImplement.h

Posted: 27 Mar 2024, 20:47
by jsantos
For NS_IMPLEMENT_REFLECTION2, 'helper' is not used, fix is adding '[[maybe_unused]]':
Same with NS_IMPLEMENT_INLINE_REFLECTION3:
For cases where the reflection block is empty, we provide NS_IMPLEMENT_REFLECTION_ and NS_IMPLEMENT_INLINE_REFLECTION_. These macros are provided in a separate header (ReflectionImplementEmpty.h) to optimize compiling in this specific scenarios.
class BaseNullable
{
public:
    NS_IMPLEMENT_INLINE_REFLECTION_(BaseNullable, NoParent)
};
We still don't support C++17, but definitely [maybe_unused] could be used here. Could you please create a ticket for this?

Re: Clang compile issues with unused variable in ReflectionImplement.h

Posted: 27 Mar 2024, 20:48
by jsantos
So it might be worth trying that build path, as it ships with VS and uses the Microsoft-provided clang-cl (if you tick the right installer option), thus some of the code in e.g. CompilerSettings.h has issues.
Could you please also report this? So far we haven't tried Visual Studio with clang.