[LLVMbugs] [Bug 12683] New: incorrect handling of non-type template parameter packs

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Apr 27 02:55:35 PDT 2012


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

             Bug #: 12683
           Summary: incorrect handling of non-type template parameter
                    packs
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: mitchnull+llvm at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


non-type template parameter pack deduction, or sizeof... gets confused if used
with non-type template parameter(s) with default values, using enable_if.

The following example only works if compiled with -DFOO1.
The second foo() should never get instantiated / considered.

#include <type_traits>

#ifdef FOO1
template <bool... Bs, typename std::enable_if<(sizeof...(Bs) == 1), bool>::type
= false>
void foo() {
        static_assert(sizeof...(Bs) == 1, "sizeof...(Bs) changed during
compilation");
}
#endif

#ifdef FOO2
template <bool... Bs, typename std::enable_if<(sizeof...(Bs) == 2), bool>::type
= false>
void foo() {
        static_assert(sizeof...(Bs) == 2, "sizeof...(Bs) changed during
compilation");
}
#endif

int main() {
        foo<true>();
}


compiler output (FOO1):

$ ~/llvm-clang-3.1-rc1-freebsd9-i386/bin/clang++ -I. -DFOO1  -std=c++11 -o sf1
sf1.cpp

compiler output (FOO2):

$ ~/llvm-clang-3.1-rc1-freebsd9-i386/bin/clang++ -I. -DFOO2  -std=c++11 -o sf1
sf1.cpp
sf1.cpp:13:2: error: static_assert failed "sizeof...(Bs) changed during
compilation"
        static_assert(sizeof...(Bs) == 2, "sizeof...(Bs) changed during
compilation");
        ^             ~~~~~~~~~~~~~~~~~~
sf1.cpp:18:2: note: in instantiation of function template specialization
'foo<true, false>' requested here
        foo<true>();
        ^
1 error generated.

compiler output (FOO1 and FOO2):

$ ~/llvm-clang-3.1-rc1-freebsd9-i386/bin/clang++ -I. -DFOO1 -DFOO2  -std=c++11
-o sf1 sf1.cpp
sf1.cpp:18:2: error: call to 'foo' is ambiguous
        foo<true>();
        ^~~~~~~~~
sf1.cpp:5:6: note: candidate function [with Bs = <true>, $1 = false]
void foo() {
     ^
sf1.cpp:12:6: note: candidate function [with Bs = <true>, $1 = false]
void foo() {
     ^
1 error generated.

-- 
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