[LLVMbugs] [Bug 20430] New: Improper handling of pointers to arrays as template parameters
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jul 23 21:18:25 PDT 2014
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: unassignedclangbugs at nondot.org
Reporter: myriachan at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140724/8425bc41/attachment.html>
More information about the llvm-bugs
mailing list