Skip to content

[BUG] Wrong constexpr initialization #801

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
ekherit opened this issue Nov 3, 2023 · 1 comment · Fixed by #924
Closed

[BUG] Wrong constexpr initialization #801

ekherit opened this issue Nov 3, 2023 · 1 comment · Fixed by #924
Labels
bug Something isn't working

Comments

@ekherit
Copy link

ekherit commented Nov 3, 2023

Description
Operator "==" works fine for initializing constexpr parameters for simple types. However, incorrect code is generated for types that initialized via initializer_list or for types with complex (with more then one parameters) constructor.

To reproduce

    x : int = 1;
    xc : int == 1;
    
    a : std::array = (1,2,3);
    ac : std::array == (4,5,6);

    v: std::vector = (1,2,3);
    vc: std::vector == (1,2,3);    

    t : mytype = (5,6,7);
    tc : mytype == (5,6,7);

Generates

    int x {1}; 
    int constexpr xc = 1; //OK
    
    std::array a {1, 2, 3}; 
    std::array constexpr ac = (4, 5, 6); //BUG

    std::vector v {1, 2, 3}; 
    std::vector constexpr vc = (1, 2, 3); //BUG

    mytype t {5,6,7}; 
    mytype constexpr tc = (5, 6, 7); //BUG

Expected result

    int x {1}; 
    int constexpr xc = 1;
    
    std::array a {1, 2, 3}; 
    std::array constexpr ac{4, 5, 6};

    std::vector v {1, 2, 3}; 
    std::vector constexpr vc{1, 2, 3};

    mytype t {5,6,7}; 
    mytype constexpr tc{5,6,7};

Additional context
Trunk version of cppfront at godbolt.org

@ekherit ekherit added the bug Something isn't working label Nov 3, 2023
@JohelEGP
Copy link
Contributor

JohelEGP commented Nov 3, 2023

This is #699.

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

Successfully merging a pull request may close this issue.

2 participants