-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[cxx-interop] Do not import function templates with a parameter pack #91410
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
Open
patrykstefanski
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
patrykstefanski:bail-on-function-template-parameter-packs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/Interop/Cxx/templates/Inputs/function-template-parameter-pack.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #ifndef TEST_INTEROP_CXX_TEMPLATES_INPUTS_FUNCTION_TEMPLATE_PARAMETER_PACK_H | ||
| #define TEST_INTEROP_CXX_TEMPLATES_INPUTS_FUNCTION_TEMPLATE_PARAMETER_PACK_H | ||
|
|
||
| // Those below include 'pack'/'Pack' in their names on purpose. We will grep by | ||
| // name to ensure they are not imported. | ||
|
|
||
| template <typename... Ts> | ||
| void takesPack(Ts... ts) {} | ||
|
|
||
| template <typename T, typename... Ts> | ||
| void takesTypeAndPack(T t, Ts... ts) {} | ||
|
|
||
| template <typename... Ts> | ||
| void unusedPack() {} | ||
|
|
||
| template <typename... Ts> | ||
| int packInReturnTypeOnly() { | ||
| return sizeof...(Ts); | ||
| } | ||
|
|
||
| // The struct should be included, but not its member functions. | ||
| struct HasVariadicTemplateMembers { | ||
| template <typename... Ts> | ||
| void memberTakesPack(Ts... ts) {} | ||
|
|
||
| template <typename... Ts> | ||
| static void staticMemberTakesPack(Ts... ts) {} | ||
| }; | ||
|
|
||
| #endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_FUNCTION_TEMPLATE_PARAMETER_PACK_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/Interop/Cxx/templates/function-template-parameter-pack-module-interface.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // RUN: %target-swift-ide-test \ | ||
| // RUN: -print-module \ | ||
| // RUN: -module-to-print=FunctionTemplateParameterPack \ | ||
| // RUN: -I %S/Inputs \ | ||
| // RUN: -source-filename=x \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: | %FileCheck %s --implicit-check-not Pack --implicit-check-not pack | ||
|
|
||
| // Ensure that function templates with a template parameter pack are not | ||
| // imported. In our test, those contain 'pack'/'Pack' in their names, so we use | ||
| // --implicit-check-not to verify that. The struct HasVariadicTemplateMembers | ||
| // itself should be printed. | ||
|
|
||
| // CHECK: struct HasVariadicTemplateMembers |
33 changes: 33 additions & 0 deletions
33
test/Interop/Cxx/templates/function-template-parameter-pack-typechecker.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // RUN: %target-typecheck-verify-swift \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: -I %S/Inputs | ||
| // RUN: %target-typecheck-verify-swift \ | ||
| // RUN: -cxx-interoperability-mode=default \ | ||
| // RUN: -enable-experimental-feature ImportCxxMembersLazily \ | ||
| // RUN: -I %S/Inputs | ||
| // | ||
| // REQUIRES: swift_feature_ImportCxxMembersLazily | ||
|
|
||
| import FunctionTemplateParameterPack | ||
|
|
||
| // Function templates with a template parameter pack are not imported. Try to | ||
| // call them anyway to make sure we don't crash trying to resolve them. | ||
|
|
||
| public func callFreeFunctionTemplatesWithPack() { | ||
| takesPack(1, Ts: CInt.self) | ||
| // expected-error@-1{{cannot find 'takesPack' in scope}} | ||
| takesTypeAndPack(1, 2, Ts: CInt.self) | ||
| // expected-error@-1{{cannot find 'takesTypeAndPack' in scope}} | ||
| unusedPack(Ts: CInt.self) | ||
| // expected-error@-1{{cannot find 'unusedPack' in scope}} | ||
| let _ = packInReturnTypeOnly(Ts: CInt.self) | ||
| // expected-error@-1{{cannot find 'packInReturnTypeOnly' in scope}} | ||
| } | ||
|
|
||
| public func callMemberFunctionTemplatesWithPack( | ||
| _ s: inout HasVariadicTemplateMembers) { | ||
| s.memberTakesPack(1, Ts: CInt.self) | ||
| // expected-error@-1{{value of type 'HasVariadicTemplateMembers' has no member 'memberTakesPack'}} | ||
| HasVariadicTemplateMembers.staticMemberTakesPack(1, Ts: CInt.self) | ||
| // expected-error@-1{{type 'HasVariadicTemplateMembers' has no member 'staticMemberTakesPack'}} | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably hoist this check into
importNameImpland save some cycles on name lookup. I don't think this is very important though.