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

            Bug ID: 20430
           Summary: Improper handling of pointers to arrays as template
                    parameters
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

The following code outputs 1 instead of 5, as if the template parameter were
decaying to "const char *" instead of being the proper "const char (*)[5]":

#include <cstdio>

template <const char (*STR)[5]>
unsigned TestBug()
{
    return sizeof(*STR);
}

extern const char g_meow[5] = "meow";

int main()
{
    std::printf("%u\n", TestBug<&g_meow>());
    return 0;
}

This works correctly if TestBug were to take STR as a runtime parameter,
including constexpr functions evaluated at compile time.  For example, the
following code prints 5:

#include <cstdio>

constexpr unsigned TestBug(const char (*STR)[5])
{
    return sizeof(*STR);
}

extern const char g_meow[5] = "meow";

template <unsigned N>
struct Number
{
    enum ValueType : unsigned { Value = N };
};

int main()
{
    std::printf("%u\n",
static_cast<unsigned>(Number<TestBug(&g_meow)>::Value));
    return 0;
}

This is all possibly related to bug 6226 or its fix, from the description of
that bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to