[LLVMbugs] [Bug 13970] New: constexpr function rejected as non const

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Sep 28 01:37:47 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13970

             Bug #: 13970
           Summary: constexpr function rejected as non const
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: leonid at volnitsky.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


With clang 3.2 from 9/19/2012 trunk clang rejects constexpr function as
non-const.  Curiously, GCC have very similar bug, where constexpr function is
rejected as non-const only in overload resolution (gcc bug 54648)

Artificial example:

#include <type_traits>
#include <vector>
#include <iostream>
using namespace std;


template <typename T>
struct is_range_t {
        template < class U, class I = typename U::const_iterator >
        static int8_t
        test(U* u);

        template <typename U>
        static int16_t
        test(...);

        enum { value  =  sizeof test<T> (0) == 1 };
};

template<typename T>
constexpr bool
is_range() { return  is_range_t<T>::value; };


// SFINAE f() 
template<class T>
typename std::enable_if< is_range<T>(), bool>::type
f() { return true; }

template<class T>
typename std::enable_if<!is_range<T>(), bool>::type
f() { return false; }

int main () {

        //  here is_range() is constepxr
        static_assert(is_range<vector<int>>(), "is-const-expr test");

        //  here is_range() is constepxr too
        return f<vector<int>>();

        // ERROR clang says that is_range() is not constexpr
        //return f<int>();
}

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list