Skip to content

[BUG] Can't declare variable/parameter of type pointer to function #718

Closed

Description

@ntrel

Describe the bug
cppfront errors when attempting to do this.

To Reproduce

f: (a: *() -> int) = {}
callback.cpp2(3,9): error: '*'/'const' type qualifiers must be followed by a type name or '_' wildcard (at '(')

Using a type alias also fails:

F: type == () -> int;
f: (a: *F) = {}
callback.cpp2(1,13): error: a 'type ==' alias declaration must be followed by a type name

Activity

  1. added
    bugSomething isn't working
    on Oct 2, 2023
  2. JohelEGP commented on Oct 2, 2023

    @JohelEGP
    Contributor

    This is #711 and #343.

  3. ntrel commented on Oct 2, 2023

    @ntrel
    ContributorAuthor

    Those use std::function, a template type, whereas this is about parsing a pointer to function type. Though it looks like #526 would fix this too.

  4. JohelEGP commented on Oct 2, 2023

    @JohelEGP
    Contributor

    They're all about being able to name function types.
    To name a pointer to function type,
    you need to name a function type.

  5. hsutter commented on Jul 27, 2024

    @hsutter
    Owner

    Thanks! Your code is now working with PR #1183:

    F: type == () -> int;
    f1: (a: *F)         = std::cout << a();
    f2: (a: *() -> int) = std::cout << a();
    
    g: () -> int = 42;
    
    main: () = {
        f1(g&);
        f2(g&);
    }
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