Skip to content

[BUG] no match for operator<< and const cpp2::nonesuch_ #961

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

Closed
wolfseifert opened this issue Feb 4, 2024 · 4 comments
Closed

[BUG] no match for operator<< and const cpp2::nonesuch_ #961

wolfseifert opened this issue Feb 4, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@wolfseifert
Copy link

After pulling in 510eae8:

main: () = {
  a: std::any = 1;
  std::cout << a as int << std::endl;
  std::cout << a as int << std::endl;
}

transpiles to

#define CPP2_IMPORT_STD          Yes
#include "cpp2util.h"
auto main() -> int;
auto main() -> int{
  std::any a {1}; 
  std::cout << cpp2::as_(a) << std::endl;
  std::cout << cpp2::as_(std::move(a)) << std::endl;
}

but does not compile

anys.cpp:10:13: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream’} and ‘const cpp2::nonesuch_’)
   10 |   std::cout << cpp2::as_(a) << std::endl;
      |   ~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~
      |        |                     |
      |        |                     const cpp2::nonesuch_
      |        std::ostream {aka std::basic_ostream}
@wolfseifert wolfseifert added the bug Something isn't working label Feb 4, 2024
@sookach
Copy link
Contributor

sookach commented Apr 25, 2024

I believe this issue can be fixed. The most recent version generates the expected c++:

std::cout << cpp2::impl::as_<int>(a) << std::endl;
std::cout << cpp2::impl::as_<int>(cpp2::move(a)) << std::endl;

@wolfseifert
Copy link
Author

I can confirm that the transpiler output changed to:

#define CPP2_IMPORT_STD          Yes
#include "cpp2util.h"
auto main() -> int;
auto main() -> int{
  std::any a {1}; 
  std::cout << cpp2::impl::as_(a) << std::endl;
  std::cout << cpp2::impl::as_(cpp2::move(a)) << std::endl;
}

but trying to compile still gives:

anys.cpp:10:13: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'const cpp2::nonesuch_')
   10 |   std::cout << cpp2::impl::as_(a) << std::endl;
      |   ~~~~~~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~
      |        |                           |
      |        |                           const cpp2::nonesuch_
      |        std::ostream {aka std::basic_ostream}

@sookach
Copy link
Contributor

sookach commented Apr 26, 2024

Ah, my bad. I'll see what I can do to fix it.

@hsutter
Copy link
Owner

hsutter commented May 15, 2024

Thanks! This should now be fixed with the above commit, please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants