Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ITK build failed due to error C2244 on MSVC + permissive- on windows #506

Closed
QuellaZhang opened this Issue Feb 14, 2019 · 9 comments

Comments

Projects
None yet
4 participants
@QuellaZhang
Copy link

QuellaZhang commented Feb 14, 2019

ITK failed when build with /permissive- by msvc on Windows, I use latset version 4773ca0 on master branch. Could you please help look at this?

You can repro this issue as the steps below:

  1. git clone http://itk.org/ITK.git D:\ITK\src
  2. open VS2017 x86 command prompt as admin and browse to D:\ITK
  3. set CL=/D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /permissive- /Zc:twoPhase-
  4. mkdir build_x86 && pushd build_x86
  5. cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=ON -DBUILD_EXAMPLES=OFF ..\src\
  6. msbuild /m /p:Configuration=Release;Platform=Win32 All_BUILD.vcxproj /t:Rebuild

Failures:

ITKCommonHeaderTest1.cxx
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): error C2244: 'itk::VectorContainer<TElementIdentifier,TElement>::ElementAt': unable to match function definition to an existing declaration
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(37): note: see declaration of 'itk::VectorContainer<TElementIdentifier,TElement>::ElementAt'
::ElementAt(ElementIdentifier id)
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): note: definition
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): note: 'VectorContainer<TElementIdentifier,TElement>::reference itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier)'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): note: existing declarations
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): note: 'const _Ty &itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier) const'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(38,1): note: '_Ty &itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier)'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): error C2244: 'itk::VectorContainer<TElementIdentifier,TElement>::ElementAt': unable to match function definition to an existing declaration
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(52): note: see declaration of 'itk::VectorContainer<TElementIdentifier,TElement>::ElementAt'
::ElementAt(ElementIdentifier id) const
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): note: definition
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): note: 'VectorContainer<TElementIdentifier,TElement>::const_reference itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier) const'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): note: existing declarations
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): note: 'const _Ty &itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier) const'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(53,1): note: '_Ty &itk::VectorContainer<TElementIdentifier,TElement>::ElementAt(TElementIdentifier)'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(69,1): error C2244: 'itk::VectorContainer<TElementIdentifier,TElement>::CreateElementAt': unable to match function definition to an existing declaration
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(68): note: see declaration of 'itk::VectorContainer<TElementIdentifier,TElement>::CreateElementAt'
::CreateElementAt(ElementIdentifier id)
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(69,1): note: definition
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(69,1): note: 'VectorContainer<TElementIdentifier,TElement>::reference itk::VectorContainer<TElementIdentifier,TElement>::CreateElementAt(TElementIdentifier)'
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(69,1): note: existing declarations
{
^
D:\ITK\src\Modules\Core\Common\include\itkVectorContainer.hxx(69,1): note: '_Ty &itk::VectorContainer<TElementIdentifier,TElement>::CreateElementAt(TElementIdentifier)'
{
^
@N-Dekker

This comment has been minimized.

Copy link
Contributor

N-Dekker commented Feb 14, 2019

Thanks @QuellaZhang I'm preparing a possible fix now :-)

N-Dekker added a commit to N-Dekker/ITK that referenced this issue Feb 14, 2019

COMP: Trailing return types (reference, const_reference) VectorContainer
Member function return types `typename VectorContainer::const_reference` and
`typename VectorContainer::reference` triggered compile errors on MSVC
(VS2017), when using /permissive- (Standards conformance), as reported by
@QuellaZhang issue InsightSoftwareConsortium#506:

    itkVectorContainer.hxx(38,1): error C2244: 'itk::VectorContainer<TElementIdentifier,TElement>::ElementAt': unable to match function definition to an existing declaration

This commit declares them as trailing return types, in order to fix this issue.
@N-Dekker

This comment has been minimized.

Copy link
Contributor

N-Dekker commented Feb 14, 2019

@QuellaZhang Please check my proposed fix: #507

@QuellaZhang

This comment has been minimized.

Copy link
Author

QuellaZhang commented Feb 15, 2019

@N-Dekker Thank you. Verified that your fix works, ITK passed under /permissive- mode when building on MSVC.

@N-Dekker

This comment has been minimized.

Copy link
Contributor

N-Dekker commented Feb 15, 2019

Thanks for verifying, @QuellaZhang

@phcerdan asked at #507 (comment)

is there any difference on the type with this? Or is just a "workaround" for keeping happy MSVC?

Do you possibly have an answer?

@N-Dekker

This comment has been minimized.

Copy link
Contributor

N-Dekker commented Feb 15, 2019

Looks like this is a minimal example:

template <typename T>
struct Vector
{
  using NestedType = int;
};

template <typename T>
class Container: public Vector<T>
{
    using typename Vector<T>::NestedType;
    NestedType Get();
};

template <typename T>
typename Container<T>::NestedType Container<T>::Get()
{
    return 42;
}

int main() { }

VS2017 compiler output:

F:\X\Src\MyProject>cl c.cpp /permissive-
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27026.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

c.cpp
c.cpp(18): error C2244: 'Container::Get': unable to match function definition to an existing declaration
c.cpp(17): note: see declaration of 'Container::Get'
c.cpp(18): note: definition
c.cpp(18): note: 'Container::NestedType Container::Get(void)'
c.cpp(18): note: existing declarations
c.cpp(18): note: 'int Container::Get(void)'

@QuellaZhang

This comment has been minimized.

Copy link
Author

QuellaZhang commented Feb 19, 2019

I am confirming with relevant personnel now.

@QuellaZhang

This comment has been minimized.

Copy link
Author

QuellaZhang commented Mar 21, 2019

@N-Dekker. Sorry for misleading, this is a problem with MSVC. Can you go back to the original source code? Sorry again.

@dzenanz

This comment has been minimized.

Copy link
Member

dzenanz commented Mar 21, 2019

Going back to original source code is extra effort, and the change @N-Dekker made might have silenced another warning on Red Hat. Is it a problem if source code stays as it is?

@QuellaZhang

This comment has been minimized.

Copy link
Author

QuellaZhang commented Mar 22, 2019

Hi, @dzenanz, I verified whether it's the latest or the original source code, we can get a clean build of ITK.

@dzenanz dzenanz closed this Mar 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.