2
カスタムトレイトとbool型のC++ 11列挙型を使用する場合は、次のコードは、グラムで罰金コンパイル++と打ち鳴らすと(私がテストしたすべてのバージョンを)失敗:コンパイルエラー
#include <iostream>
namespace has_insertion_operator_impl
{
typedef char no;
typedef char yes[2];
struct any_t
{
template <typename T>
any_t(const T&);
};
yes& testStreamable(std::ostream&);
no testStreamable(no);
no operator<<(const std::ostream&, const any_t&);
template <typename T>
struct has_insertion_operator
{
static std::ostream& s;
static const T& t;
static const bool value = sizeof(testStreamable(s << t)) == sizeof(yes);
};
} // namespace has_insertion_operator_impl
template <typename T>
struct has_insertion_operator : has_insertion_operator_impl::has_insertion_operator<T>
{};
enum A : bool {
Yup = true,
Nop = false,
};
template <typename T>
bool getTraitVal(const T&) { return has_insertion_operator<T>::value; }
int main() { std::cout << getTraitVal(A::Yup) << std::endl; }
エラーは(これだけで!)
prog.cc:24:59: error: use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' (aka 'basic_ostream<char>') and 'const A')
static const bool value = sizeof(testStreamable(s << t)) == sizeof(yes);
私はこれが十分小さい例だと思います。私はintにBOOLから列挙型を変更すると
- エラーが消える:ここではそれのためのオンラインのコンパイラへのリンクです。
なぜこのようなことが起こっていますか?これはもともと、doctestとCatchのテストフレームワークを使用して発見されました。ここにはCatchのbug reportがあります。それはclangバグでしょうか?
多分私達が打ち鳴らすためにバグを提出しようとする必要があります - 誰もが持ってアカウント? – onqtam
バグ報告 - [こちら](https://llvm.org/bugs/show_bug.cgi?id=31229) – onqtam