[llvm-bugs] [Bug 26594] New: Compilation error with typdef, template expansion and conditional
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Feb 12 10:24:51 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=26594
Bug ID: 26594
Summary: Compilation error with typdef, template expansion and
conditional
Product: clang
Version: 3.7
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: joe_woodbury at yahoo.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 15892
--> https://llvm.org/bugs/attachment.cgi?id=15892&action=edit
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 at 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
--
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/20160212/3c65f936/attachment-0001.html>
More information about the llvm-bugs
mailing list