SuperElastix / elastix

Official elastix repository
http://elastix.dev
Apache License 2.0
449 stars 110 forks source link

COMP: Add `(void)` casts to `inputPixelTypeHolder` parameters of GTests #1138

Closed N-Dekker closed 3 weeks ago

N-Dekker commented 3 weeks ago

Fixes MSVC /W4 warnings, saying:

warning C4100: 'inputPixelTypeHolder': unreferenced formal parameter

Note that [[maybe_unused]] cannot be used in these case, because of a compiler bug in MSVC 2022, which would produce:

error C2187: syntax error: 'attribute specifier' was unexpected here

This error occurs with an auto parameter of a lambda, when the capture list [] is empty.

N-Dekker commented 3 weeks ago

Minimal example of why [[maybe_unused]] could not be used:

auto lambda = []([[maybe_unused]] auto param)
{
    return 0;
};

MSVC compiler output:

<source>(4): error C2187: syntax error: 'attribute specifier' was unexpected here
<source>(7): error C2938: '<lambda_ec40d5d9873b467271aa3bde8867069a>::<lambda_typedef_cdecl>' : Failed to specialize alias template
<source>(7): note: the template instantiation context (the oldest one first) is
<source>(7): note: see reference to alias template instantiation '<lambda_ec40d5d9873b467271aa3bde8867069a>::<lambda_typedef_cdecl><_T1>' being compiled
<source>(7): error C2938: '<lambda_ec40d5d9873b467271aa3bde8867069a>::<lambda_typedef_vectorcall>' : Failed to specialize alias template
<source>(7): note: the template instantiation context (the oldest one first) is
<source>(7): note: see reference to alias template instantiation '<lambda_ec40d5d9873b467271aa3bde8867069a>::<lambda_typedef_vectorcall><_T1>' being compiled
<source>(7): error C2535: '<lambda_ec40d5d9873b467271aa3bde8867069a>::operator unknown-type(void) noexcept const': member function already defined or declared
<source>(7): note: see declaration of '<lambda_ec40d5d9873b467271aa3bde8867069a>::operator unknown-type'
Compiler Passes:
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\cl.exe:        Version 19.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\c1.dll:        Version 19.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\c1xx.dll:      Version 19.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\c2.dll:        Version 19.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\c1xx.dll:      Version 19.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\link.exe:      Version 14.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\mspdb140.dll:  Version 14.39.33321.0
 C:\data\msvc\14.39.33321-Pre\bin\Hostx64\x64\1033\clui.dll: Version 19.39.33321.0

From https://godbolt.org/z/x853db9cM