Skip to content

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

Closed

Description

@wolfseifert

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}

Activity

  1. sookach commented on Apr 25, 2024

    @sookach
    Contributor

    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;
  2. wolfseifert commented on Apr 26, 2024

    @wolfseifert
    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}
    
  3. sookach commented on Apr 26, 2024

    @sookach
    Contributor

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

  4. hsutter commented on May 15, 2024

    @hsutter
    Owner

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

  5. added a commit that references this issue on May 15, 2024
    4b1b255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions