[llvm-bugs] [Bug 50953] New: Missing optimization: if constexpr(false) prevents NRVO

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 1 03:23:06 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50953

            Bug ID: 50953
           Summary: Missing optimization: if constexpr(false) prevents
                    NRVO
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: antoshkka at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Consider the following code:

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

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

A test() {
  return foo<false>();
}


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

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210701/52e8027e/attachment-0001.html>


More information about the llvm-bugs mailing list