c++ - Unexpected conversion in regular initialization -
clang 3.2 reports error in following code, , not understand why there problem. error occurs in template function, , if braces used initialization. other 2 initializations work expected.
struct foo { foo() { }; ~foo() = default; // deleted foo(const foo& rhs) = delete; foo(foo&& rhs) noexcept = delete; auto operator=(const foo& rhs) -> foo& = delete; auto operator=(foo&& rhs) noexcept -> foo& = delete; }; template <typename type> void bar() { foo a; // ok foo b{}; // error } int main() { foo c{}; // ok bar<int>(); } if compile code clang++ -wall -std=c++11 -c, clang prints following error message:
bug.cpp:14:9: error: conversion function 'foo' 'foo' invokes deleted function foo b{}; // error ^ bug.cpp:19:5: note: in instantiation of function template specialization 'bar<int>' requested here bar<int>(); ^ bug.cpp:6:5: note: function has been explicitly marked deleted here foo(foo&& rhs) noexcept = delete; ^ 1 error generated. i have no idea why clang tries conversion. sounds bug. unfortunately, have problem in more complex code base, solution not easy removing braces.
why clang need conversion in case? , how can working in general?
this bug. there no reason why attempt should made invoke move constructor, since have default initialization:
foo b{}; // same "foo b;" in case if copy initialization involved, things different, not case.
besides, code compiles fine on gcc 4.7.2.
Comments
Post a Comment