<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Compilation error with typdef, template expansion and conditional"
href="https://llvm.org/bugs/show_bug.cgi?id=26594">26594</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Compilation error with typdef, template expansion and conditional
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>joe_woodbury@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15892" name="attach_15892" title="The source code cited in the description.">attachment 15892</a> <a href="attachment.cgi?id=15892&action=edit" title="The source code cited in the description.">[details]</a></span>
The source code cited in the description.
I'm not sure how to summarize, this the following builds on the latest MSC 2015
update 1 and g++ 5.3, but not clang 3.7 or 3.7.1. The following code has been
severely reduced from the original. There may be a better way to do this and
I'm very open to the possibility that clang is right and Microsoft and g++ are
wrong.
If TEST_TYPEDEF is defined, the generates the following error on clang 3.7.x.
The static_assert is correct; the question is why is it generating that
operator:
[jwoodbury@joew test]$ clang -c -std=c++14 test.cpp
test.cpp:9:5: error: static_assert failed "uint8_t, uint16_t, uint32_t
required."
static_assert(std::is_same<T, uint8_t>::value || std::is_same<T,
uint16_t>::value ||
^
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:71:20: note: in instantiation of template class
'bit_pack<bit_pack<unsigned int>::prohibit_operator_uint16_conversion>'
requested here
const lmap bit16 = bit_pack_factory<16>::nth_bit();
/////////////////////////////////////
#include <cstddef>
#include <cstdint>
#include <limits>
#include <type_traits>
template <typename T>
struct bit_pack
{
static_assert(std::is_same<T, uint8_t>::value || std::is_same<T,
uint16_t>::value ||
std::is_same<T, uint32_t>::value, "uint8_t, uint16_t, uint32_t
required.");
class prohibit_operator_uint16_conversion {};
class prohibit_operator_uint32_conversion {};
typedef T Type;
bit_pack() : the_backing_store(0)
{
}
bit_pack(T const& value) : the_backing_store(value)
{
}
operator bit_pack<typename std::conditional<
sizeof(T) <= sizeof(uint16_t), uint16_t,
prohibit_operator_uint16_conversion>::type>() const
{
return bit_pack<uint16_t>(the_backing_store);
}
operator bit_pack<typename std::conditional<
sizeof(T) <= sizeof(uint32_t), uint32_t,
prohibit_operator_uint32_conversion>::type>() const
{
return bit_pack<uint32_t>(the_backing_store);
}
T the_backing_store;
};
#define TEST_TYPEDEF
#ifdef TEST_TYPEDEF
typedef bit_pack<uint8_t> bmap;
typedef bit_pack<uint16_t> wmap;
typedef bit_pack<uint32_t> lmap;
#define BIT_PACK_NTH_BIT_MAP_TYPE \
typename std::conditional<bit_index < 8, bmap, typename
std::conditional<bit_index < 16, wmap, lmap>::type>::type
#else
#define BIT_PACK_NTH_BIT_MAP_TYPE \
typename std::conditional<bit_index < 8, uint8_t, typename
std::conditional<bit_index < 16, uint16_t, uint32_t>::type>::type
#endif
template <size_t bit_index>
struct bit_pack_factory
{
static BIT_PACK_NTH_BIT_MAP_TYPE nth_bit()
{
// With clang and TEST_TYPEDEF, this does not give a warning
BIT_PACK_NTH_BIT_MAP_TYPE const result = 1u << bit_index;
return result;
}
};
#ifdef TEST_TYPEDEF
const lmap bit16 = bit_pack_factory<16>::nth_bit();
#else
bit_pack<uint32_t> bit_pack_int = bit_pack_factory<16>::nth_bit();
#endif</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>