[llvm-bugs] [Bug 33089] New: Static value in depended class is treated as non-constant expression.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 18 01:46:48 PDT 2017


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

            Bug ID: 33089
           Summary: Static value in depended class is treated as
                    non-constant expression.
           Product: clang
           Version: 3.9
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: tomaszkam at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

For following code:
#include <type_traits>

template<typename U, typename T>
decltype(U{T::value}) foo(T, int) { return T::value; }

template<typename U, typename T>
U foo(T, ...) = delete;

int main()
{
    foo<short>(std::integral_constant<int, 20>{}, 0);
}

Candidate foo(T, int) is ignored with following error:
  substitution failure [with U = short, T = std::__1::integral_constant<int,
20>]: non-constant-expression cannot be narrowed from type 'int' to 'short' in
initializer list decltype(U{T::value}) foo(T, int) { return T::value; }
As suggested the T::value is not constexpr expression, despite declared as
constexpr.

If the declaration is changed to us an compile time conversion operator, the
expression is properly regonized as compile time constant, and brace
initialization is well-formed. 
template<typename U, typename T>
decltype(U{T{}}) foo(T, int) { return T::value; }

-- 
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/20170518/90043bd7/attachment.html>


More information about the llvm-bugs mailing list