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

[interop] C++ extension for class template specialization isn't visible when forward declaration for it is present #62165

Open
hyp opened this issue Nov 17, 2022 · 0 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler in itself

Comments

@hyp
Copy link
Contributor

hyp commented Nov 17, 2022

Swift fails to compile a file as it can't find a method in an extension for a C++ class template, when this template specialization typealias is in module B, and module A defines it and has a forward declaration for this template.

Steps to reproduce:
$ cat test.h

#pragma once

template<class T>
struct TestStruct;

TestStruct<int> returnStruct();

template<class T>
struct TestStruct {
    int xy;
};

$ cat test3.h

#pragma once
#include "test.h"

using TestStructInt = TestStruct<int>;

$ cat module.modulemap

module Testi {
  header "test.h"
  requires cplusplus
}

module Testi3 {
  header "test3.h"
  requires cplusplus
}

$ cat test.swift

import Testi
import Testi3

extension TestStructInt {

public func testExtensionFunc() {
  print("Hey, this is extension speaking")
}

}

$ cat test2.swift

import Testi
import Testi3
import TestExt

func test() {
   let t = TestStructInt()
   t.testExtensionFunc()
}

invoke:
$ bin/swiftc -sdk $SDK -emit-module -module-name TestExt test.swift -I . -Xfrontend -enable-experimental-cxx-interop
$ bin/swiftc -sdk $SDK -emit-module -module-name TestProd test2.swift -I . -Xfrontend -enable-experimental-cxx-interop

RESULT:

test2.swift:8:6: error: value of type 'TestStructInt' (aka '__CxxTemplateInst10TestStructIiE') has no member 'testExtensionFunc'
   t.testExtensionFunc()
   ~ ^~~~~~~~~~~~~~~~

Expected result:

Should compile.

If I remove the forward declaration from test.h, it works.

@hyp hyp added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ labels Nov 17, 2022
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants