Skip to content

COMP: making it compile on VS2017#2759

Closed
dzenanz wants to merge 1 commit intoInsightSoftwareConsortium:masterfrom
dzenanz:fixVS2017
Closed

COMP: making it compile on VS2017#2759
dzenanz wants to merge 1 commit intoInsightSoftwareConsortium:masterfrom
dzenanz:fixVS2017

Conversation

@dzenanz
Copy link
Copy Markdown
Member

@dzenanz dzenanz commented Sep 27, 2021

The regression was introduced by 4f30980.

WIP. Reduces number of compile failures on Visual Studio 2017 on My computer. I plan to get back to this later this week.

The regression was introduced by 4f30980.
@github-actions github-actions Bot added area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings labels Sep 27, 2021
@N-Dekker
Copy link
Copy Markdown
Contributor

@dzenanz FYI, I did an similar partial revert for VS2107 on elastix! SuperElastix/elastix@fd523e5

Specifically to work around VS2107 compiler bug "Compile error when using "using declaration" referencing a base class type that refers to itself", EssentiaX - Reported March 12, 2019 [Fixed in version 16.2], https://developercommunity.visualstudio.com/t/486683

The compile error only seemed to appear when the type that the class was "using" was actually a base class.

@dzenanz
Copy link
Copy Markdown
Member Author

dzenanz commented Sep 28, 2021

I saw SuperElastix/elastix@fd523e5. I tried that first, but then realized that using X = Superclass::X; works in VS2017 too.

Comment on lines +57 to +70
using PixelType = typename Superclass::PixelType; \
using CellType = typename Superclass::CellType; \
using CellAutoPointer = typename Superclass::CellAutoPointer; \
using CellConstAutoPointer = typename Superclass::CellConstAutoPointer; \
using CellRawPointer = typename Superclass::CellRawPointer; \
using CellConstRawPointer = typename Superclass::CellConstRawPointer; \
using CellTraits = typename Superclass::CellTraits; \
using CoordRepType = typename Superclass::CoordRepType; \
using InterpolationWeightType = typename Superclass::InterpolationWeightType; \
using PointIdentifier = typename Superclass::PointIdentifier; \
using PointIdIterator = typename Superclass::PointIdIterator; \
using PointIdConstIterator = typename Superclass::PointIdConstIterator; \
using CellIdentifier = typename Superclass::CellIdentifier; \
using CellFeatureIdentifier = typename Superclass::CellFeatureIdentifier; \
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure all of these changes are necessary, for VS2017? I had the impression that the VS2017 error "C2886: symbol cannot be used in a member using-declaration" only occurred when the "type to be used" itself is a base-class of the class that has the using-declaration. (Compiler bug https://developercommunity.visualstudio.com/t/486683)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are more than welcome to take over this PR, and explore the minimum amount of changes which get it compile on VS2017.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a look now, and it appears that there's another category of erroneous (!) VS2017 compile errors that we're encountering now after pull request #2567, saying:

error C2244: unable to match function definition to an existing declaration

This VS2017 compile error may be reproduced by:

template <typename T>
class Base
{
public:
  using NestedType = T;
};

template <typename T>
class Derived : public Base<T>
{
  using Superclass = Base<T>;
  using typename Superclass::NestedType;
  NestedType MemberFunction();
};

template <typename T>
typename Derived<T>::NestedType
Derived<T>::MemberFunction()
{  // <==  error C2244: unable to match function definition to an existing declaration

  return NestedType{};
}

And this particular error may be solved by a trailing return type instead:

template <typename T>
auto
Derived<T>::MemberFunction() -> NestedType
{  // OK!

  return NestedType{};
}

And in this particular case (having a nested dependent type as return type), I think it would actually be quite nice to use a trailing return type.

To be continued...

@N-Dekker
Copy link
Copy Markdown
Contributor

I saw SuperElastix/elastix@fd523e5. I tried that first, but then realized that using X = Superclass::X; works in VS2017 too.

Indeed, VS2017 supports both C++11 using type aliases and C++98 using-declarations. Only limited by compiler bugs 😸

N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Oct 5, 2021
Partially reverted pull request InsightSoftwareConsortium#2567
commit 4f30980 "STYLE: Avoid repeating parent aliases"
because of Visual Studio 2017 compile errors reported by Dženan Zukić at
InsightSoftwareConsortium#2759 "COMP: making it compile on VS2017"

Worked around the following VS2017 compile errors:

> error C2653: '...': is not a class or namespace name
> error C2886: '...': symbol cannot be used in a member using-declaration

The compiler bug that caused these errors is reported here:
"Compile error when using "using declaration" referencing a base class type that refers to itself"
EssentiaX - Reported March 12, 2019 [Fixed in version 16.2]
https://developercommunity.visualstudio.com/t/486683
@dzenanz
Copy link
Copy Markdown
Member Author

dzenanz commented Oct 5, 2021

Closing in favor of #2780.

@dzenanz dzenanz closed this Oct 5, 2021
@dzenanz dzenanz deleted the fixVS2017 branch October 5, 2021 14:26
dzenanz pushed a commit that referenced this pull request Oct 5, 2021
Partially reverted pull request #2567
commit 4f30980 "STYLE: Avoid repeating parent aliases"
because of Visual Studio 2017 compile errors reported by Dženan Zukić at
#2759 "COMP: making it compile on VS2017"

Worked around the following VS2017 compile errors:

> error C2653: '...': is not a class or namespace name
> error C2886: '...': symbol cannot be used in a member using-declaration

The compiler bug that caused these errors is reported here:
"Compile error when using "using declaration" referencing a base class type that refers to itself"
EssentiaX - Reported March 12, 2019 [Fixed in version 16.2]
https://developercommunity.visualstudio.com/t/486683
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this pull request May 6, 2026
Partially reverted pull request InsightSoftwareConsortium#2567
commit 77006be "STYLE: Avoid repeating parent aliases"
because of Visual Studio 2017 compile errors reported by Dženan Zukić at
InsightSoftwareConsortium#2759 "COMP: making it compile on VS2017"

Worked around the following VS2017 compile errors:

> error C2653: '...': is not a class or namespace name
> error C2886: '...': symbol cannot be used in a member using-declaration

The compiler bug that caused these errors is reported here:
"Compile error when using "using declaration" referencing a base class type that refers to itself"
EssentiaX - Reported March 12, 2019 [Fixed in version 16.2]
https://developercommunity.visualstudio.com/t/486683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants