Skip to content

Missing optimization: if constexpr(false) prevents NRVO #50297

Open
@apolukhin

Description

Bugzilla Link 50953
Version trunk
OS Linux
CC @apolukhin,@zygoloid

Extended Description

Consider the following code:

struct A {
A() = default;
A(A&&);
};

template
A foo() {
A a;
if constexpr (B) {
return A();
}
return a;
}

A test() {
return foo();
}

In the above example NRVO for a is applied by many compilers, but not clang.

Godbolt playground: https://godbolt.org/z/P8G3zj5GE

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions