[llvm-bugs] [Bug 42387] New: constexpr constructors for data types from -finclude-default-header

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 25 10:44:37 PDT 2019


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

            Bug ID: 42387
           Summary: constexpr constructors for data types from
                    -finclude-default-header
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: OpenCL
          Assignee: unassignedclangbugs at nondot.org
          Reporter: drohr at jwdt.org
                CC: anastasia.stulova at arm.com, llvm-bugs at lists.llvm.org

The following code

struct float3a { float x, y, z; };

constexpr float3 crossProduct(const float3& firstVector, const float3&
secondVector)
{
  return float3{ (firstVector.y * secondVector.z) - (firstVector.z *
secondVector.y),
                 (firstVector.z * secondVector.x) - (firstVector.x *
secondVector.z),
                 (firstVector.x * secondVector.y) - (firstVector.y *
secondVector.x) };
}

constexpr float3a crossProduct(const float3& firstVector, const float3&
secondVector)
{
  return float3a{ (firstVector.y * secondVector.z) - (firstVector.z *
secondVector.y),
                 (firstVector.z * secondVector.x) - (firstVector.x *
secondVector.z),
                 (firstVector.x * secondVector.y) - (firstVector.y *
secondVector.x) };
}

compiled with "clang++ -cl-std=c++ -Xclang -finclude-default-header" fails with

test.cl:3:18: error: constexpr function never produces a constant expression
[-Winvalid-constexpr]
constexpr float3 crossProduct(const float3& firstVector, const float3&
secondVector)
                 ^
test.cl:5:19: note: subexpression not valid in a constant expression
  return float3{ (firstVector.y * secondVector.z) - (firstVector.z *
secondVector.y),
                  ^
test.cl:10:19: error: functions that differ only in their return type cannot be
overloaded
constexpr float3a crossProduct(const float3& firstVector, const float3&
secondVector)
          ~~~~~~~ ^
test.cl:3:18: note: previous definition is here
constexpr float3 crossProduct(const float3& firstVector, const float3&
secondVector)

since apparently one cannot create a float3 from -finclude-default-header in a
constexpr way, while it works with the manually-defined float3a.

-- 
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/20190625/d94396c5/attachment.html>


More information about the llvm-bugs mailing list