Skip to content

[BUG] UFCS doesn't work at namespace scope #314

Description

@JohelEGP

Describe the bug
error: non-local lambda expression cannot have a capture-default.

To Reproduce
Steps to reproduce the behavior:

  1. Sample code - distilled down to minimal essentials please
f: (x)->int = 0;
y: int = 0.f();
Generated code
//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "x.cpp2"
[[nodiscard]] auto f(auto const& x) -> int;
extern int y;
//=== Cpp2 function definitions =================================================

#line 1 "x.cpp2"
[[nodiscard]] auto f(auto const& x) -> int { return 0;  }
int y {CPP2_UFCS_0(f, 0)}; 
  1. Command lines including which C++ compiler you are using
~/root/bin/cppfront x.cpp2 
~/root/clang/bin/clang++ -std=c++20 -I $CPPFRONT_INCLUDE_DIR x.cpp
clang version 17.0.0
  1. Expected result - what you expected to happen
    UFCS to work at namespace scope. By using a different macro that doesn't use a capture-default.

  2. Actual result/error

x.cpp2:2:8: error: non-local lambda expression cannot have a capture-default
int y {CPP2_UFCS_0(f, 0)}; 
       ^
/home/johel/Documents/C++/Forks/cppfront/include/cpp2util.h:646:2: note: expanded from macro 'CPP2_UFCS_0'
[&](auto&& obj) CPP2_FORCE_INLINE_LAMBDA -> decltype(auto) { \
 ^
1 error generated.

Activity

  1. filipsajdak commented on Apr 2, 2023

    @filipsajdak
    Contributor

    @JohelEGP I think it would be good to see what cpp1 code is generated (in such issues).

    I will generate it by myself but it will give more context than the error message from cpp1 compiler.

  2. JohelEGP commented on Apr 2, 2023

    @JohelEGP
    ContributorAuthor

    Good idea. Updated, rebased on main.

  3. filipsajdak commented on Apr 2, 2023

    @filipsajdak
    Contributor

    @JohelEGP your lamda returns void.

    Please correct your code to:

    f: (x) -> _ = 0;
    y := 0.f();
  4. filipsajdak commented on Apr 2, 2023

    @filipsajdak
    Contributor

    Ah, your updated code is fine.

  5. hsutter commented on Apr 2, 2023

    @hsutter
    Owner

    Thanks! Fixing in next commit...

  6. hsutter commented on Apr 3, 2023

    @hsutter
    Owner

    Incidentally, I think you win the prize for the issue that is resolved by the commit that exactly doubles the line count of cppfront from the day I first introduced it at CppCon 2022 about six months ago when it was 9 KLOC... this commit just took us over the 18 KLOC mark. (Still quite svelte! Circle is over 10x as big I think.)

  7. JohelEGP commented on Apr 3, 2023

    @JohelEGP
    ContributorAuthor

    the issue

    The first issue so far. ☺

    I'm looking forward to the seeing the numbers when cppfront self-hosts.

  8. added a commit that references this issue on Dec 5, 2023
    d875731
  9. added a commit that references this issue on Feb 4, 2024
    827ed79
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