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

Python - fix compilation error with the latest MSVC (version 14.41) #3009

Closed

Conversation

liangtie
Copy link

Add the missing typename qualifier to the template parameter for swig::SwigPyIterator_T and swig::container_owner

Closes #3008

…120)

Add the missing typename qualifier to the template parameter for swig::SwigPyIterator_T and swig::container_owner

Closes swig#3008
@ojwb
Copy link
Member

ojwb commented Aug 30, 2024

There are still CI failures in the MSVC jobs which look like the same issue.

Add the missing typename qualifier to the template parameter for swig::SwigPyIterator_T and swig::container_owner

FWIW typename here is called a "disambiguator" rather than a "qualifier".

…120)

Add the typename disambiguator for Make_output_iterator and SwigValueWrapper.
.gitignore Outdated Show resolved Hide resolved
Source/Swig/swig.h Outdated Show resolved Hide resolved
return 1;
return 0;
}

Copy link
Member

Choose a reason for hiding this comment

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

The type string containing iterator just can't be the right condition here. What's the problem this is trying to solve?

Copy link
Author

@liangtie liangtie Sep 2, 2024

Choose a reason for hiding this comment

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

For statements using SwigValueWrapper with an iterator type as its template argument, e.g.

SwigValueWrapper< std::vector< enum EnumVector::numbers >::reverse_iterator > result;

MSVC (version 14.41) requires a typename prefix to compile, like this:

SwigValueWrapper< typename std::vector< enum EnumVector::numbers >::reverse_iterator > result;

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a problem with iterators only?
Perhaps a more strict matching?
Like '::iterator' or '::[a-z]+_iterator' regular expression?

Copy link
Contributor

@erezgeva erezgeva Sep 2, 2024

Choose a reason for hiding this comment

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

Looking here:
https://en.cppreference.com/w/cpp/iterator#Iterator_adaptors

There are many iterator types:
Some follow [a-z_]+_iterator.
But some are shorten like
inserter for insert_iterator

If we need to add this to all iterators type, seems we need a dictionary.

Did you find any document from Microsoft on the last VC++ change that require typename?

Copy link
Contributor

@erezgeva erezgeva Sep 2, 2024

Choose a reason for hiding this comment

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

Looking on
https://en.cppreference.com/w/cpp/keyword/typename
and
https://learn.microsoft.com/en-gb/cpp/cpp/typename

It is more than iterators.
Seems this fix need a bigger change.

  1. What changed in VC++ that suddenly need the typename, do they have a configuration/flag that control this.
  2. If we do wish to add typename we need to follow the standard and do that in all cases, not just an ad-hoc fixing of the iterators we found.

Copy link
Member

Choose a reason for hiding this comment

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

It won't be anything to do with iterators as such, and certainly not with types containing the substring iterator, so please let's not go further down the rabbit hole of trying to conditionalise this on the type name.

There's something about these types that requires this, and we need to work out what it actually is (I'm guessing you tried always including the typename disambiguator but that breaks some other cases?)

It's unclear to me if the new MSVC is buggy here or if other compilers (including older MSVC) are just lenient in coping without the typename disambiguator, but I guess even if MSVC is buggy we may want to work around it.

If this isn't an MSVC bug then Microsoft's attitude to compatibility seems frustratingly inconsistent - they don't declare __cplusplus correctly by default because they worry it will break stuff (despite not declaring it correctly breaking stuff for people who are not working in a Microsoft-only bubble) yet they seem happy to break stuff like this with only a minor version bump.

@wsfulton
Copy link
Member

wsfulton commented Sep 4, 2024

Adding typename is not the way forward for working around a buggy compiler. Adding in the enum prefix breaks the code and the same buggy compiler will work without the enum prefix, so the type information is full and complete and also works with other compilers. The proposed solution here is a horrible specific hack for one particular type and won't necessarily work around all similar bugs in the compiler. Please use #3008 for discussing further solutions.

@wsfulton wsfulton closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSVC 17.11 is buggy and fails to compile some SWIG-generated wrappers involving enums
4 participants