Skip to content

[BUG] UFCS macro broken given object v<a, b> #493

Closed

Description

@JohelEGP

Title: UFCS macro broken given object v<a, b>.

Minimal reproducer (https://cpp2.godbolt.org/z/14rxj4Gv3):

main: () -> int = std::variant<i8, i8>().index();
Commands:
cppfront -clean-cpp1 main.cpp2
clang++17 -std=c++23 -stdlib=libc++ -lc++abi -pedantic-errors -Wall -Wextra -Wconversion -I . main.cpp

Expected result:

Program returned: 0

Actual result and error:

[[nodiscard]] auto main() -> int { return CPP2_UFCS_0(index, std::variant<cpp2::i8,cpp2::i8>());  }
Cpp2 lowered to Cpp1.
#include "cpp2util.h"


[[nodiscard]] auto main() -> int;

[[nodiscard]] auto main() -> int { return CPP2_UFCS_0(index, std::variant<cpp2::i8,cpp2::i8>());  }

Output.

build/_cppfront/main.cpp:8:84: error: too many arguments provided to function-like macro invocation
    8 | [[nodiscard]] auto main() -> int { return CPP2_UFCS_0(index, std::variant<cpp2::i8,cpp2::i8>());  }
      |                                                                                    ^
raw.githubusercontent.com/hsutter/cppfront/main/include/cpp2util.h:705:9: note: macro 'CPP2_UFCS_0' defined here
  705 | #define CPP2_UFCS_0(FUNCNAME,PARAM1) \
      |         ^

Activity

  1. tsoj commented on Oct 21, 2023

    @tsoj
    Contributor

    Also happens with [] braces, e.g:

    Position: type = {
        operator[]: (this, p: int, c: int) -> int = 0;
    }
    
    main: () -> int = Position()[0, 0].abs();

    (Relevant for C++23)

  2. JohelEGP commented on Oct 21, 2023

    @JohelEGP
    ContributorAuthor

    Yeah:

    main.cpp2:5:74: error: too many arguments provided to function-like macro invocation
        5 | [[nodiscard]] auto main() -> int { return CPP2_UFCS_0(abs, Position()[0, 0]);  }
          |                                                                          ^
    

    That's fixed by #506.

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